[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ add ReanalyzeRequired exception, correct a bug where not the original algebra was stored in RunnableQuery
Adam Groszer
agroszer at gmail.com
Wed Aug 13 04:26:05 EDT 2008
Log message for revision 89787:
add ReanalyzeRequired exception, correct a bug where not the original algebra was stored in RunnableQuery
Changed:
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/runnablequery.py
U Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
U Sandbox/adamg/ocql/trunk/src/ocql/engine.py
A Sandbox/adamg/ocql/trunk/src/ocql/exceptions.py
U Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py
D Sandbox/adamg/ocql/trunk/src/ocql/ocqlexception.py
U Sandbox/adamg/ocql/trunk/src/ocql/tests/test_metadata.py
-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -30,12 +30,10 @@
self.context = context
#self.db = db
- def __call__(self, metadata, algebra):
- algebra = self.context.tree
- #code = algebra.compile()
- adapter = IAlgebraCompiler(algebra)
+ def __call__(self, metadata, originalAlgebra):
+ adapter = IAlgebraCompiler(self.context.tree)
code = adapter()
- run = RunnableQuery(metadata, self.context, code)
+ run = RunnableQuery(metadata, originalAlgebra, code)
return run
class BaseCompiler(object):
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/runnablequery.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/runnablequery.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/runnablequery.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -10,6 +10,7 @@
from ocql.interfaces import IAlgebraOptimizer
from ocql.interfaces import IAlgebraCompiler
+from ocql.exceptions import ReanalyzeRequired
_marker = object()
@@ -52,10 +53,10 @@
metadata: ocql.metadata instance
alg: algebra object
"""
- def __init__(self, metadata, alg, code):
+ def __init__(self, metadata, originalAlgebra, code):
self.metadata = metadata
- self.alg = alg
- self.code =code
+ self.alg = originalAlgebra
+ self.code = code
def __repr__(self):
return "%s: %s" % (self.__class__.__name__,
@@ -64,9 +65,14 @@
def reanalyze(self):
optimizedalgebra = IAlgebraOptimizer(self.alg)(self.metadata)
runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata, optimizedalgebra)
- return runnable
- def execute(self, debug=False):
+ self.metadata = runnable.metadata
+ self.alg = runnable.alg
+ self.code = runnable.code
+
+ return self
+
+ def execute(self, debug=False, noretry=False):
#TODO: why is the metadata not working in locals?
mapping = {'metadata': self.metadata,
@@ -77,4 +83,10 @@
mapping['range'] = d_range
mapping['set'] = d_set
- return eval(self.code, mapping, mapping)
+ try:
+ return eval(self.code, mapping, mapping)
+ except ReanalyzeRequired:
+ if noretry:
+ raise
+ self.reanalyze()
+ return eval(self.code, mapping, mapping)
Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -12,7 +12,7 @@
from ocql.interfaces import IDB
from ocql.database.index import AllIndex
-from ocql.ocqlexception import OCQLException
+from ocql.exceptions import ReanalyzeRequired
class MetaType:
def get_property(self, name):
@@ -125,7 +125,7 @@
obj_list = [intids.getObject(result) for result in results]
return obj_list
- raise OCQLException("reanalyze required")
+ raise ReanalyzeRequired()
def hasPropertyIndex(self, klass, property):
catalogs = getUtilitiesFor(ICatalog)
Modified: Sandbox/adamg/ocql/trunk/src/ocql/engine.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/engine.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/engine.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -40,6 +40,7 @@
optimizedoq = IQueryOptimizer(objectquery)()
algebra = IRewriter(optimizedoq)()
optimizedalgebra = IAlgebraOptimizer(algebra)(metadata)
- runnable = IAlgebraCompiler(optimizedalgebra)(metadata, optimizedalgebra)
+ #algebra is passed here to keep track of the original one, not the optimized
+ runnable = IAlgebraCompiler(optimizedalgebra)(metadata, algebra)
return runnable
Copied: Sandbox/adamg/ocql/trunk/src/ocql/exceptions.py (from rev 89785, Sandbox/adamg/ocql/trunk/src/ocql/ocqlexception.py)
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/exceptions.py (rev 0)
+++ Sandbox/adamg/ocql/trunk/src/ocql/exceptions.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -0,0 +1,17 @@
+# -*- coding: UTF-8 -*-
+
+from zope.interface import implements
+from ocql.interfaces import IOCQLException
+from ocql.interfaces import IReanalyzeRequired
+
+class OCQLException(Exception):
+ implements(IOCQLException)
+
+ def __init__(self, message=None):
+ self.message = message
+
+ def getMessage(self):
+ return self.message
+
+class ReanalyzeRequired(OCQLException):
+ implements(IReanalyzeRequired)
Modified: Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -116,6 +116,10 @@
contents of the database
"""
+################
+#
+################
+
class IOCQLException(Interface):
"""General exception
"""
@@ -126,6 +130,10 @@
"""Returns exception message
"""
+class IReanalyzeRequired(IOCQLException):
+ """Reanalyze Required, something changed in the metadata
+ """
+
################
#
################
Deleted: Sandbox/adamg/ocql/trunk/src/ocql/ocqlexception.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/ocqlexception.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/ocqlexception.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -1,13 +0,0 @@
-# -*- coding: UTF-8 -*-
-
-from zope.interface import implements
-from ocql.interfaces import IOCQLException
-
-class OCQLException(Exception):
- implements(IOCQLException)
-
- def __init__(self, message):
- self.message = message
-
- def getMessage(self):
- return self.message
\ No newline at end of file
Modified: Sandbox/adamg/ocql/trunk/src/ocql/tests/test_metadata.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/tests/test_metadata.py 2008-08-13 08:21:57 UTC (rev 89786)
+++ Sandbox/adamg/ocql/trunk/src/ocql/tests/test_metadata.py 2008-08-13 08:26:04 UTC (rev 89787)
@@ -23,6 +23,7 @@
from ocql.testing.utils import setupInterfaces, setupCatalog
from ocql.tests.test_old import QueryNullParser
from ocql.testing.sample.student import Student
+from ocql.exceptions import ReanalyzeRequired
import ocql.compiler.compiler
import ocql.rewriter.rewriter
@@ -42,14 +43,8 @@
self.engine = OCQLEngine()
- def compare(self, qo, expected):
- run = self.engine.compile(qo)
- self.delete_index()
- result = run.execute()
-
- #self.assertEqual(expected, result)
-
- def test_metadata(self):
+ def test_metadata_reanalyze(self):
+ #check to see how ReanalyzeRequired works
metadata = IDB(None)
symbols = SymbolContainer()
@@ -73,21 +68,34 @@
Identifier(metadata, symbols, '"USA"'))
], Identifier(metadata, symbols, 'c.name')))
- self.compare(qo, "Traceback (most recent call last): ....")
-#set([metadata.getFromIndex('IStudent', 'country','==', 'USA')[0].name])
+ try:
+ run = self.engine.compile(qo)
+ self.assert_('metadata.getFromIndex("IStudent", "country", "==", "USA"))' in run.code)
- def delete_index(self):
- """
- >>> delete_index()
- Traceback (most recent call last):
- ...
- """
+ self.delete_index('student_country')
+
+ #no reanalyze here, raises exception
+ result = run.execute(noretry=True)
+
+ self.fail("ReanalyzeRequired expected")
+ except ReanalyzeRequired:
+ pass
+
+ #reanalyze here, no exception, returns result
+ result = run.execute()
+
+ #code changes
+ self.assert_('metadata.getAll("IStudent"))' in run.code)
+
+
+
+ def delete_index(self, todel):
metadata = IDB(None)
catalogs = getUtilitiesFor(ICatalog)
intids = getUtility(IIntIds)
for name, catalog in catalogs:
for iname, index in catalog.items():
- if iname == 'student_country':
+ if iname == todel:
del catalog[iname]
def test_suite():
More information about the Checkins
mailing list