[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ add tests to test metadata.getFromIndex by deleting the index

Charith Paranaliyanage paranaliyanage at gmail.com
Wed Aug 13 01:08:46 EDT 2008


Log message for revision 89779:
  add tests to test metadata.getFromIndex by deleting the index

Changed:
  U   Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/engine.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/tests/test_old.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py

-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -97,29 +97,16 @@
     adapts(IIter)
 
     def __call__(self):
-        if self.context.func is LambdaCompiler and \
-        self.context.coll is set and \
-        self.context.expr is IfCompiler:
+        if self.context.klass == set:
+            return 'reduce(set.union, map(%s, %s), set())' % (
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.coll)())
+        if self.context.klass == list:
+            return 'reduce(operator.add, map(%s, %s), [])' % (
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.coll)())
 
-            if self.context.klass == set:
-                return 'reduce(set.union, map(%s, %s), set())' % (
-                    IAlgebraCompiler(self.context.func)(),
-                    IAlgebraCompiler(self.context.coll)())
-            if self.context.klass == list:
-                return 'reduce(operator.add, map(%s, %s), [])' % (
-                    IAlgebraCompiler(self.context.func)(),
-                    IAlgebraCompiler(self.context.coll)())
-        else:
-            if self.context.klass == set:
-                return 'reduce(set.union, map(%s, %s), set())' % (
-                    IAlgebraCompiler(self.context.func)(),
-                    IAlgebraCompiler(self.context.coll)())
-            if self.context.klass == list:
-                return 'reduce(operator.add, map(%s, %s), [])' % (
-                    IAlgebraCompiler(self.context.func)(),
-                    IAlgebraCompiler(self.context.coll)())
 
-
 class SelectCompiler(BaseCompiler):
     implements(IAlgebraCompiler)
     adapts(ISelect)

Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -12,6 +12,7 @@
 
 from ocql.interfaces import IDB
 from ocql.database.index import AllIndex
+from ocql.ocqlexception import OCQLException
 
 class MetaType:
     def get_property(self, name):
@@ -123,10 +124,9 @@
 
                     obj_list = [intids.getObject(result) for result in results]
                     return obj_list
-        #I could check whether property has an index by hasPropertyIndex. 
-        #But by this approach this always returns IF objects
-        return self.getAll(klass)
 
+        raise OCQLException("reanalyze required")
+
     def hasPropertyIndex(self, klass, property):
         catalogs = getUtilitiesFor(ICatalog)
         for name, catalog in catalogs:
@@ -137,7 +137,6 @@
                     return True
         return False
 
-
     def get_class(self, klassname):
         """Returns a MetaType instance for the class."""
         return self.classes[klassname]

Modified: Sandbox/adamg/ocql/trunk/src/ocql/engine.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/engine.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/engine.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -36,7 +36,7 @@
             objectquery = query
         else:
             objectquery = IQueryParser(query)(metadata)
-        
+
         optimizedoq = IQueryOptimizer(objectquery)()
         algebra = IRewriter(optimizedoq)()
         optimizedalgebra = IAlgebraOptimizer(algebra)(metadata)

Modified: Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/interfaces.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -7,6 +7,7 @@
 
 from zope.interface import Interface
 from zope.interface import Attribute
+from zope.schema import Text
 
 ################
 # Components
@@ -115,6 +116,16 @@
         contents of the database
         """
 
+class IOCQLException(Interface):
+    """General exception
+    """
+
+    message = Text()
+
+    def getMessage():
+        """Returns exception message
+        """
+
 ################
 #
 ################

Modified: Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt	2008-08-13 05:08:45 UTC (rev 89779)
@@ -64,11 +64,9 @@
     >>> print str(alg)
     Iter(<type 'list'>, Lambda i: Single(<type 'list'>, i), Make(<type 'list'>, <type 'set'>, ICourse))
 
-    #>>> qo = QueryParser("set [ c in ICourse; c.credits>3 | c.code ]")(TestMetadata())
-    #>>> opt = QueryOptimizer(qo)()
-    #>>> alg = Rewriter(opt)()
-    #>>> print str(alg)
-    #Iter(<type 'set'>, Lambda c: If(c.credits>`3`, Single(<type 'set'>, c.code), Empty(<type 'set'>)), Make(<type 'set'>, <type 'set'>, ICourse))
+    >>> qo = QueryParser("set [ c in ICourse; c.credits>3 | c.code ]")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Iter(<type 'set'>, Lambda c: If(c.credits>`3`, Single(<type 'set'>, c.code), Empty(<type 'set'>)), Make(<type 'set'>, <type 'set'>, ICourse))
 
-
-    #bag not implemented

Modified: Sandbox/adamg/ocql/trunk/src/ocql/tests/test_old.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/tests/test_old.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/tests/test_old.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -26,7 +26,8 @@
 from ocql.compiler.compiler import AlgebraCompiler
 from ocql.testing.database import TestMetadata
 
-from ocql.compiler.compiler import registerAdapters
+import ocql.compiler.compiler
+import ocql.rewriter.rewriter
 
 from ocql.testing.database import C1, C2, C3
 from ocql.testing.database import D1, D2, D3
@@ -57,7 +58,8 @@
         provideAdapter(AlgebraOptimizer)
         provideAdapter(AlgebraCompiler)
         provideAdapter(TestMetadata)
-        registerAdapters()
+        ocql.compiler.compiler.registerAdapters()
+        ocql.rewriter.rewriter.registerAdapters()
 
         self.engine = OCQLEngine()
 

Modified: Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py	2008-08-13 04:30:44 UTC (rev 89778)
+++ Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py	2008-08-13 05:08:45 UTC (rev 89779)
@@ -19,8 +19,9 @@
 from ocql.testing.utils import setupInterfaces, setupCatalog
 from ocql.tests.test_old import QueryNullParser
 from ocql.testing.sample.student import Student
+import ocql.compiler.compiler
+import ocql.rewriter.rewriter
 
-
 db = {}
 
 classes = {}
@@ -34,7 +35,8 @@
         provideAdapter(AlgebraOptimizer)
         provideAdapter(AlgebraCompiler)
         provideAdapter(Metadata)
-        registerAdapters()
+        ocql.compiler.compiler.registerAdapters()
+        ocql.rewriter.rewriter.registerAdapters()
         setupInterfaces(self)
         setupCatalog(self)
 



More information about the Checkins mailing list