[Checkins] SVN: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/ move initialization to __init__

Adam Groszer agroszer at gmail.com
Mon Jul 14 12:33:43 EDT 2008


Log message for revision 88360:
  move initialization to __init__ 
  move property setting to a common method

Changed:
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py

-=-
Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py	2008-07-14 15:51:59 UTC (rev 88359)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py	2008-07-14 16:33:42 UTC (rev 88360)
@@ -23,10 +23,10 @@
         directlyProvides(obj, directlyProvidedBy(obj), marker)
 
 def visit(algebra):
+    #print str(algebra)
     if isinstance(algebra , BaseAlgebra):
         for child in algebra.children:
             visit(child)
-    print str(algebra)
 
 class AlgebraOptimizer(object):
     implements(IAlgebraOptimizer)
@@ -40,6 +40,3 @@
         addMarkerIF(self.context, IOptimizedAlgebraObject)
         visit(self.context.tree)
         return self.context
-    
-
-

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt	2008-07-14 15:51:59 UTC (rev 88359)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt	2008-07-14 16:33:42 UTC (rev 88360)
@@ -91,6 +91,8 @@
     Lambda i: If(i.value==5, Single(<type 'set'>, i.name), Empty(<type 'set'>)),
     Make(<type 'set'>, <type 'set'>, IUnOptimizedClass))
 
+Results of the query:
+
     >>> result = run.execute()
     >>> result
     set([u'5'])

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py	2008-07-14 15:51:59 UTC (rev 88359)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py	2008-07-14 16:33:42 UTC (rev 88360)
@@ -16,6 +16,7 @@
 from ocql.interfaces import IAlgebraObjectHead
 from ocql.rewriter.interfaces import *
 from zope.location import Location, locate
+from zope.location.interfaces import ILocation
 
 class Head(Location):
     implements(IAlgebraObjectHead)
@@ -30,8 +31,16 @@
 
 class BaseAlgebra(Location):
     implements(IAlgebraObject)
-    children = []
 
+    def __init__(self):
+        self.children = []
+
+    def setProp(self, name, value):
+        setattr(self, name, value)
+        if ILocation.providedBy(value):
+            locate(value, self, name)
+            self.children.append(value)
+
     def walk(self):
         yield self
         for child in self.children:
@@ -43,7 +52,8 @@
     implements(IEmpty)
 
     def __init__(self, klass, expr):
-        self.klass = klass
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
 
     def __repr__(self):
         return 'Empty(%s)'%(self.klass)
@@ -54,10 +64,9 @@
     implements(ISingle)
 
     def __init__(self, klass, expr):
-        self.klass = klass
-        self.expr = expr
-        locate(expr, self, 'expr')
-        self.children.extend([klass, expr])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('expr', expr)
 
     def __repr__(self):
         return 'Single(%s, %s)'%(self.klass, self.expr)
@@ -67,12 +76,10 @@
     implements(IUnion)
 
     def __init__(self, klass, coll1, coll2):
-        self.klass=klass
-        self.coll1=coll1
-        self.coll2=coll2
-        locate(coll1, self, 'coll1')
-        locate(coll2, self, 'coll2')
-        self.children.extend([coll1, coll2])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('coll1', coll1)
+        self.setProp('coll2', coll2)
 
     def __repr__(self):
         return 'Union(%s, %s, %s)'%(self.klass, self.coll1, self.coll2)
@@ -80,7 +87,7 @@
 
 #class Differ:
 #    def __init__(self, klass, start, end):
-#        self.klass = klass
+#        self.setProp('klass', klass)
 #        self.start = start
 #        self.end = end
 #
@@ -96,12 +103,10 @@
     implements(IIter)
 
     def __init__(self, klass, func, coll):
-        self.klass = klass
-        self.func = func
-        self.coll = coll
-        locate(func, self, 'func')
-        locate(coll, self, 'coll')
-        self.children.extend([func,coll])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('func', func)
+        self.setProp('coll', coll)
 
     def __repr__(self):
         return "Iter(%s, %s, %s)"%(self.klass, self.func, self.coll)
@@ -112,12 +117,10 @@
     implements(ISelect)
 
     def __init__(self, klass, func, coll):
-        self.klass = klass
-        self.func = func
-        self.coll = coll
-        locate(func, self, 'func')
-        locate(coll, self, 'coll')
-        self.children.extend([func,coll])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('func', func)
+        self.setProp('coll', coll)
 
     def __repr__(self):
         return "Select(%s, %s, %s)"%(self.klass, self.func, self.coll)
@@ -128,16 +131,12 @@
     implements(IReduce)
 
     def __init__(self, klass, expr, func, aggreg, coll):
-        self.klass = klass
-        self.expr = expr
-        self.func = func
-        self.aggreg = aggreg
-        self.coll = coll
-        locate(expr, self, 'expr')
-        locate(func, self, 'func')
-        locate(aggreg, self, 'aggreg')
-        locate(coll, self, 'coll')
-        self.children.extend([expr, func, aggreg, coll])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('expr', expr)
+        self.setProp('func', func)
+        self.setProp('aggreg', aggreg)
+        self.setProp('coll', coll)
 
     def __repr__(self):
         return "Reduce(%s, %s, %s, %s, %s)"%(self.klass, self.expr, self.func, self.aggreg, self.coll)
@@ -145,9 +144,9 @@
 
 #class Equal:
 #    def __init__(self, klass, coll1, coll2):
-#        self.klass = klass
-#        self.coll1 = coll1
-#        self.coll2 = coll2
+#        self.setProp('klass', klass)
+#        self.setProp('coll1', coll1)
+#        self.setProp('coll2', coll2)
 #
 #    def compile(self):
 #        if self.klass == set:
@@ -160,12 +159,10 @@
     implements(IRange)
 
     def __init__(self, klass, start, end):
-        self.klass = klass
-        self.start = start
-        self.end = end
-        locate(start, self, 'start')
-        locate(end, self, 'end')
-        self.children.extend([start, end])
+        BaseAlgebra.__init__(self)
+        self.setProp('klass', klass)
+        self.setProp('start', start)
+        self.setProp('end', end)
 
 
 #class Index
@@ -175,13 +172,10 @@
     implements(IMake)
 
     def __init__(self, coll1, coll2, expr):
-        self.expr = expr
-        self.coll1 = coll1
-        self.coll2 = coll2
-        locate(expr, self, 'expr')
-#        locate(coll1, self, 'coll1')
-#        locate(coll2, self, 'coll2')
-        self.children.append(expr)
+        BaseAlgebra.__init__(self)
+        self.setProp('expr', expr)
+        self.setProp('coll1', coll1)
+        self.setProp('coll2', coll2)
 
     def __repr__(self):
         return "Make(%s, %s, %s)" %(self.coll1, self.coll2, self.expr)
@@ -195,13 +189,10 @@
     implements(IIf)
 
     def __init__(self, cond, expr1, expr2):
-        self.cond = cond
-        self.expr1 = expr1
-        self.expr2 = expr2
-        locate(cond, self, 'cond')
-        locate(expr1, self, 'expr1')
-        locate(expr2, self, 'expr2')
-        self.children.extend([cond, expr1, expr2])
+        BaseAlgebra.__init__(self)
+        self.setProp('cond', cond)
+        self.setProp('expr1', expr1)
+        self.setProp('expr2', expr2)
 
     def __repr__(self):
         return "If(%s, %s, %s)" % (self.cond, self.expr1, self.expr2)
@@ -215,10 +206,9 @@
     implements(ILambda)
 
     def __init__(self, var, expr):
-        self.var = var
-        self.expr = expr
-        locate(expr, self, 'expr')
-        self.children.append(expr)
+        BaseAlgebra.__init__(self)
+        self.setProp('var', var)
+        self.setProp('expr', expr)
 
     def __repr__(self):
         return "Lambda %s: %s" %(self.var, self.expr)
@@ -229,6 +219,7 @@
     implements(IConstant)
 
     def __init__(self, value):
+        BaseAlgebra.__init__(self)
         self.value = value
 
     def __repr__(self):
@@ -240,6 +231,7 @@
     implements(IIdentifier)
 
     def __init__(self, name):
+        BaseAlgebra.__init__(self)
         self.name=name
 
     def __repr__(self):
@@ -250,12 +242,10 @@
     implements(IBinary)
 
     def __init__(self, left, op, right):
-        self.left = left
-        self.op = op
-        self.right = right
-        locate(left, self, 'left')
-        locate(right, self, 'right')
-        self.children.extend([left, right])
+        BaseAlgebra.__init__(self)
+        self.setProp('left', left)
+        self.setProp('op', op)
+        self.setProp('right', right)
 
     def __repr__(self):
         return "%s%s%s" % (self.left, self.op.op, self.right)
@@ -266,6 +256,7 @@
     implements(IOperator)
 
     def __init__(self, op):
+        BaseAlgebra.__init__(self)
         self.op = op
 
     def __repr__(self):



More information about the Checkins mailing list