[Checkins] SVN: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/ minor name changes, rearranged things around IAlgebraObject and IAlgebraObjectHead

Adam Groszer agroszer at gmail.com
Mon Jul 7 12:32:26 EDT 2008


Log message for revision 88083:
  minor name changes, rearranged things around IAlgebraObject and IAlgebraObjectHead

Changed:
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/aoptimizer/aoptimizer.py
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/algebra.py
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/interfaces.py

-=-
Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/aoptimizer/aoptimizer.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/aoptimizer/aoptimizer.py	2008-07-07 16:03:56 UTC (rev 88082)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/aoptimizer/aoptimizer.py	2008-07-07 16:32:26 UTC (rev 88083)
@@ -14,7 +14,7 @@
 
 from ocql.interfaces import IAlgebraOptimizer
 
-from ocql.interfaces import IAlgebraObject
+from ocql.interfaces import IAlgebraObjectHead
 from ocql.interfaces import IOptimizedAlgebraObject
 
 def addMarkerIF(obj, marker):
@@ -24,7 +24,7 @@
 
 class AlgebraOptimizer(object):
     implements(IAlgebraOptimizer)
-    adapts(IAlgebraObject)
+    adapts(IAlgebraObjectHead)
 
     def __init__(self, context):
         self.context = context

Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py	2008-07-07 16:03:56 UTC (rev 88082)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py	2008-07-07 16:32:26 UTC (rev 88083)
@@ -13,7 +13,7 @@
 from zope.component import provideAdapter
 
 from ocql.interfaces import IAlgebraCompiler
-from ocql.interfaces import IAlgebraPartCompiler
+#from ocql.interfaces import IAlgebraCompiler
 from ocql.interfaces import IOptimizedAlgebraObject
 #from ocql.interfaces import ICompiledAlgebraObject
 from ocql.rewriter.algebra import Head
@@ -31,14 +31,11 @@
         #self.db = db
 
     def __call__(self, metadata, algebra):
-        if isinstance(algebra, Head):
-            algebra = self.context.tree
-        else:
-            algebra = self.context
+        algebra = self.context.tree
         #code = algebra.compile()
-        adapter = IAlgebraPartCompiler(algebra)
+        adapter = IAlgebraCompiler(algebra)
         code = adapter()
-        run = RunnableQuery(metadata, algebra, code)
+        run = RunnableQuery(metadata, self.context, code)
         return run
 
 class BaseCompiler(object):
@@ -47,7 +44,7 @@
         self.context = context
 
 class EmptyCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IEmpty)
 
     def __call__(self):
@@ -57,31 +54,31 @@
             return '[]'
 
 class SingleCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(ISingle)
 
     def __call__(self):
         if self.context.klass == set:
-            return 'set(['+IAlgebraPartCompiler(self.context.expr)()+'])'
+            return 'set(['+IAlgebraCompiler(self.context.expr)()+'])'
         elif self.context.klass == list:
-            return '['+IAlgebraPartCompiler(self.context.expr)()+']'
+            return '['+IAlgebraCompiler(self.context.expr)()+']'
 
 class UnionCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IUnion)
 
     def __call__(self):
         if self.context.klass == set:
             return 'set.union(%s, %s)' % (
-                IAlgebraPartCompiler(self.context.coll1)(),
-                IAlgebraPartCompiler(self.context.coll2)())
+                IAlgebraCompiler(self.context.coll1)(),
+                IAlgebraCompiler(self.context.coll2)())
         elif self.context.klass == list:
             return '(%s)+(%s)' % (
-                IAlgebraPartCompiler(self.context.coll1)(),
-                IAlgebraPartCompiler(self.context.coll2)())
+                IAlgebraCompiler(self.context.coll1)(),
+                IAlgebraCompiler(self.context.coll2)())
 
 class IterCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IIter)
 
     def __call__(self):
@@ -91,105 +88,105 @@
 
             if self.context.klass == set:
                 return 'reduce(set.union, map(%s,%s), set())' % (
-                    IAlgebraPartCompiler(self.context.func)(),
-                    IAlgebraPartCompiler(self.context.coll)())
+                    IAlgebraCompiler(self.context.func)(),
+                    IAlgebraCompiler(self.context.coll)())
             if self.context.klass == list:
                 return 'reduce(operator.add, map(%s, %s), [])' % (
-                    IAlgebraPartCompiler(self.context.func)(),
-                    IAlgebraPartCompiler(self.context.coll)())
+                    IAlgebraCompiler(self.context.func)(),
+                    IAlgebraCompiler(self.context.coll)())
         else:
             if self.context.klass == set:
                 return 'reduce(set.union, map(%s,%s), set())' % (
-                    IAlgebraPartCompiler(self.context.func)(),
-                    IAlgebraPartCompiler(self.context.coll)())
+                    IAlgebraCompiler(self.context.func)(),
+                    IAlgebraCompiler(self.context.coll)())
             if self.context.klass == list:
                 return 'reduce(operator.add, map(%s, %s), [])' % (
-                    IAlgebraPartCompiler(self.context.func)(),
-                    IAlgebraPartCompiler(self.context.coll)())
+                    IAlgebraCompiler(self.context.func)(),
+                    IAlgebraCompiler(self.context.coll)())
 
 
 class SelectCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(ISelect)
 
     def __call__(self):
         if self.context.klass == set:
             return 'set(filter(%s, %s))' % (
-                IAlgebraPartCompiler(self.context.func)(),
-                IAlgebraPartCompiler(self.context.call)())
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.call)())
         if self.context.klass == list:
             return 'filter()%s, %s' % (
-                IAlgebraPartCompiler(self.context.func)(),
-                IAlgebraPartCompiler(self.context.call)())
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.call)())
 
 
 class ReduceCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IReduce)
 
     def __call__(self):
         if self.context.klass == set:
             return 'reduce(%s, map(%s, %s), %s)' % (
-                IAlgebraPartCompiler(self.context.aggreg)(),
-                IAlgebraPartCompiler(self.context.func)(),
-                IAlgebraPartCompiler(self.context.coll)(),
-                IAlgebraPartCompiler(self.context.expr)())
+                IAlgebraCompiler(self.context.aggreg)(),
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.coll)(),
+                IAlgebraCompiler(self.context.expr)())
         elif self.context.klass == list:
             return 'reduce(%s, map(%s, %s), %s)'% (
-                IAlgebraPartCompiler(self.context.aggreg)(),
-                IAlgebraPartCompiler(self.context.func)(),
-                IAlgebraPartCompiler(self.context.coll)(),
-                IAlgebraPartCompiler(self.context.expr)())
+                IAlgebraCompiler(self.context.aggreg)(),
+                IAlgebraCompiler(self.context.func)(),
+                IAlgebraCompiler(self.context.coll)(),
+                IAlgebraCompiler(self.context.expr)())
 
 
 class RangeCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IRange)
 
     def __call__(self):
         if self.context.klass == set:
             return 'set(range(%s,%s))' % (
-                IAlgebraPartCompiler(self.context.start)(),
-                IAlgebraPartCompiler(self.context.end)())
+                IAlgebraCompiler(self.context.start)(),
+                IAlgebraCompiler(self.context.end)())
         elif self.context.klass == list:
             return 'range(%s,%s)' % (
-                IAlgebraPartCompiler(self.context.start)(),
-                IAlgebraPartCompiler(self.context.end)())
+                IAlgebraCompiler(self.context.start)(),
+                IAlgebraCompiler(self.context.end)())
 
 
 class MakeCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IMake)
 
     def __call__(self):
         return '%s(metadata.getAll("%s"))' % (
             self.context.coll1.__name__,
-            IAlgebraPartCompiler(self.context.expr)())
+            IAlgebraCompiler(self.context.expr)())
 
 
 class IfCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IIf)
 
     def __call__(self):
         return '((%s) and (%s) or (%s))' % (
-            IAlgebraPartCompiler(self.context.cond)(),
-            IAlgebraPartCompiler(self.context.expr1)(),
-            IAlgebraPartCompiler(self.context.expr2)())
+            IAlgebraCompiler(self.context.cond)(),
+            IAlgebraCompiler(self.context.expr1)(),
+            IAlgebraCompiler(self.context.expr2)())
 
 
 class LambdaCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(ILambda)
 
     def __call__(self):
         return 'lambda %s: %s'%(
             self.context.var,
-            IAlgebraPartCompiler(self.context.expr)())
+            IAlgebraCompiler(self.context.expr)())
 
 
 class ConstantCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IConstant)
 
     def __call__(self):
@@ -197,7 +194,7 @@
 
 
 class IdentifierCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IIdentifier)
 
     def __call__(self):
@@ -205,18 +202,18 @@
 
 
 class BinaryCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IBinary)
 
     def __call__(self):
         return '%s%s%s' % (
-            IAlgebraPartCompiler(self.context.left)(),
+            IAlgebraCompiler(self.context.left)(),
             self.context.op.op,
-            IAlgebraPartCompiler(self.context.right)())
+            IAlgebraCompiler(self.context.right)())
 
 
 class OperatorCompiler(BaseCompiler):
-    implements(IAlgebraPartCompiler)
+    implements(IAlgebraCompiler)
     adapts(IOperator)
 
     ops = {

Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py	2008-07-07 16:03:56 UTC (rev 88082)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py	2008-07-07 16:32:26 UTC (rev 88083)
@@ -44,10 +44,6 @@
     Embeds the relation and index retrieval component information in the compiled object.
     """
 
-class IAlgebraPartCompiler(Interface):
-    #TODO: get rid of this with the real algebra tree
-    pass
-
 class IDB(Interface):
     """DB metadata and data provider
     Provides database metadata to the engine.
@@ -73,13 +69,18 @@
     as python objects
     """
 
+class IAlgebraObjectHead(Interface):
+    """Represents head of the algebra object tree
+    """
+    tree = Attribute('holds the root of the algebra object tree')
+
+    def walk(self):
+        """Iterate the Algebra object tree"""
+
 class IAlgebraObject(Interface):
     """Objects providing this interface represent the
     rewritten ObjectQuery to Algebra objects
     """
-    def compile(self):
-        """Return the compiled python code"""
-
     def walk(self):
         """Iterate the Algebra object tree"""
 

Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/algebra.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/algebra.py	2008-07-07 16:03:56 UTC (rev 88082)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/algebra.py	2008-07-07 16:32:26 UTC (rev 88083)
@@ -13,12 +13,13 @@
 from zope.interface import implements
 
 from ocql.interfaces import IAlgebraObject
+from ocql.interfaces import IAlgebraObjectHead
 from ocql.rewriter.interfaces import *
 from zope.location import Location, locate
 
-class Head:
-    implements(IHead)
-    
+class Head(Location):
+    implements(IAlgebraObjectHead)
+
     def __init__(self, tree):
         name = 'head'
         self.tree = tree
@@ -26,26 +27,16 @@
     def __repr__(self):
         return ('%s') % (self.tree)
 
-class Algebra:
-    """Signature definition of Algebra operation classes.
-    shall be moved to an IF later
-    """
-    #TODO: this is dirty here, at the end we'll need to have a tree of
-    #Algebra's whose topmost element will only get this IF
+
+class BaseAlgebra(Location):
     implements(IAlgebraObject)
     children = []
-    
-    def walk(self):
-        """Iterate the Algebra object tree"""
 
-class BaseAlgebra(Algebra, Location):
-    
     def walk(self):
         yield self
         for child in self.children:
-            if isinstance(self, Algebra):#can be removed if collection type wrapped by a algebra class
-                for t in child.walk():
-                    yield t
+            for t in child.walk():
+                yield t
 
 class Empty(BaseAlgebra):
 
@@ -57,8 +48,6 @@
     def __repr__(self):
         return 'Empty(%s)'%(self.klass)
 
-    def walk(self):
-        yield self
 
 class Single(BaseAlgebra):
 
@@ -112,7 +101,7 @@
         self.coll = coll
         locate(func, self, 'func')
         locate(coll, self, 'coll')
-        self.children.append([func,coll])
+        self.children.extend([func,coll])
 
     def __repr__(self):
         return "Iter(%s,%s,%s)"%(self.klass, self.func, self.coll)
@@ -128,8 +117,8 @@
         self.coll = coll
         locate(func, self, 'func')
         locate(coll, self, 'coll')
-        self.children.append([func,coll])
-       
+        self.children.extend([func,coll])
+
     def __repr__(self):
         return "Select(%s,%s,%s)"%(self.klass, self.func, self.coll)
 
@@ -148,7 +137,7 @@
         locate(func, self, 'func')
         locate(aggreg, self, 'aggreg')
         locate(coll, self, 'coll')
-        self.children.append([expr, func, aggreg, coll])
+        self.children.extend([expr, func, aggreg, coll])
 
     def __repr__(self):
         return "Reduce(%s,%s,%s,%s,%s)"%(self.klass, self.expr, self.func, self.aggreg, self.coll)
@@ -193,7 +182,7 @@
 #        locate(coll1, self, 'coll1')
 #        locate(coll2, self, 'coll2')
         self.children.append(expr)
-       
+
     def __repr__(self):
         return "Make(%s,%s,%s)" %(self.coll1, self.coll2, self.expr)
 
@@ -245,8 +234,6 @@
     def __repr__(self):
         return "`%s`" %(self.value)
 
-    def walk(self):
-        yield self
 
 class Identifier(BaseAlgebra):
 
@@ -258,9 +245,6 @@
     def __repr__(self):
         return "%s" % self.name
 
-    def walk(self):
-        yield self
-
 class Binary(BaseAlgebra):
 
     implements(IBinary)
@@ -287,9 +271,6 @@
     def __repr__(self):
         return self.op
 
-    def walk(self):
-        yield self
-
 #class Property:
 #   def __init__(self, left, right):
 #        self.left = left

Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/interfaces.py	2008-07-07 16:03:56 UTC (rev 88082)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/interfaces.py	2008-07-07 16:32:26 UTC (rev 88083)
@@ -4,12 +4,6 @@
 from zope.schema import Dict, Text, Int, TextLine
 from zope.interface import Attribute, Interface
 
-class IHead(IAlgebraObject):
-    """Represents head of the algebra object tree
-    """
-    __name__ = TextLine()
-    tree = Attribute('hold algebra object tree')
-    
 ################
 #Algebra operation interfaces
 ################



More information about the Checkins mailing list