[Checkins] SVN: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/ algebra tree changes for basic algebra tree optimization. Still have some test failtures

Charith Paranaliyanage paranaliyanage at gmail.com
Tue Aug 5 01:48:55 EDT 2008


Log message for revision 89358:
  algebra tree changes for basic algebra tree optimization. Still have some test failtures
  

Changed:
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.txt
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer_new.txt
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/tests.py
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/compiler.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/compiler/runnablequery.py
  U   Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/engine.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-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py	2008-08-05 05:48:53 UTC (rev 89358)
@@ -49,6 +49,7 @@
     """Replaces the identified Iter tree pattern """
     coll = tree.klass
     single = tree.func.expr.expr1
+    var = tree.func.var
     interface = tree.coll.expr1.name
     cond = tree.func.expr.cond.left.name
     operator = tree.func.expr.cond.op.op
@@ -62,16 +63,24 @@
     if operator == '==':
         makeFromIndex = MakeFromIndex(coll , coll, interface, cond.split(".")[1], value, value)
     elif operator == '>' or operator == '>=':
-        makeFromIndex = MakeFromIndex(coll , coll, interface, cond.split(".")[1], lowerbound=value)
+        makeFromIndex = MakeFromIndex(coll , coll, interface, cond.split(".")[1], lowerbound=value, upperbound='Z')
     elif operator == '<' or operator == '<=':
-        makeFromIndex = MakeFromIndex(coll , coll, interface, cond.split(".")[1], upperbound=value)
+        makeFromIndex = MakeFromIndex(coll , coll, interface, cond.split(".")[1], lowerbound='A', upperbound=value)
     else:
         return tree
     
-    newTree = Iter(coll, single, makeFromIndex)
+    newlambda = Lambda(var, single)
+    newTree = Iter(coll, newlambda, makeFromIndex)
     parent = tree.__parent__
-    locate(newTree, parent, 'iter')
-    return newTree
+    if isinstance(parent, Head):
+        return Head(newTree)
+    else:
+        for c in parent.children:
+            if isinstance(c, Iter):
+                del c
+        parent.children.append(newTree)
+        locate(newTree, parent, 'iter')
+        return newTree
 
 
 def addMarkerIF(obj, marker):
@@ -88,10 +97,12 @@
         #self.db = db
 
     def __call__(self, metadata):
-        addMarkerIF(self.context, IOptimizedAlgebraObject)
         results = findItrTreePattern(self.context.tree)
+        
         if results is not None:
-            newTree = iterPatternMatcher(results)
-            #return newTree
+            alg = iterPatternMatcher(results)
+            addMarkerIF(alg, IOptimizedAlgebraObject)
+            return alg
 
+        addMarkerIF(self.context, IOptimizedAlgebraObject)
         return self.context

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.txt
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.txt	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.txt	2008-08-05 05:48:53 UTC (rev 89358)
@@ -1,24 +1,31 @@
 
+	>>> from zope.interface.verify import verifyObject
 
+	>>> from ocql.interfaces import IAlgebraOptimizer
     >>> from ocql.aoptimizer.aoptimizer import AlgebraOptimizer
     >>> from ocql.interfaces import IOptimizedAlgebraObject
+    >>> from ocql.interfaces import IDB
 
-Currently the optimizer is doing NOTHING, it just returns what it gets.
-(And adds the interface IOptimizedAlgebraObject)
+#Currently the optimizer is doing NOTHING, it just returns what it gets.
+#(And adds the interface IOptimizedAlgebraObject)
 
     >>> class Dummy(object):
-    ...     def __init__(self, value):
-    ...          self.value = value
+    ...     def __init__(self, tree):
+    ...          self.tree = tree
 
     >>> in_=Dummy('foo-bar')
-    >>> in_.value
+    >>> in_.tree
     'foo-bar'
 
-    >>> out = AlgebraOptimizer(in_)()
+    >>> obj = AlgebraOptimizer(in_)
+	>>> verifyObject(IAlgebraOptimizer, obj)
+	True
 
+	>>> out = obj(None)
+
     >>> print out
     <Dummy object at ...>
-    >>> out.value
+    >>> out.tree
     'foo-bar'
 
     >>> IOptimizedAlgebraObject.providedBy(out)

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer_new.txt
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer_new.txt	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer_new.txt	2008-08-05 05:48:53 UTC (rev 89358)
@@ -46,7 +46,7 @@
     >>> alg = Rewriter(opt)()
     >>> out = AlgebraOptimizer(alg)(None)
     >>> print str(out)
-    Iter(<type 'set'>, Lambda c: If(c.credits>`3`, Single(<type 'set'>, c.code), Empty(<type 'set'>)), Make(<type 'set'>, <type 'set'>, ICourse))
+    Iter(<type 'set'>, Lambda c: Single(<type 'set'>, c.code), MakeFromIndex(<type 'set'>, <type 'set'>, ICourse, credits, 3, Z))
 
     #bag not implemented
     #>>> qo = QueryParser("size set [ i in ICourse | i ]")(TestMetadata())

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/tests.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/tests.py	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/tests.py	2008-08-05 05:48:53 UTC (rev 89358)
@@ -7,6 +7,8 @@
     return unittest.TestSuite((
 # avoid this tests for convenient while adding new implementation to the algebra optimizer
 #need to add aoptimizer.txt
+        DocFileSuite('aoptimizer.txt',
+            optionflags=flags),
         DocFileSuite('aoptimizer_new.txt',
             optionflags=flags),
         ))

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/compiler.py	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/compiler.py	2008-08-05 05:48:53 UTC (rev 89358)
@@ -169,7 +169,7 @@
     adapts(IMakeFromIndex)
 
     def __call__(self):
-        return '%s(metadata.getFromIndex("%s", "%s", "%s", "%s", "%s"))' % (
+        return '%s(metadata.getFromIndex("%s", "%s", %s, %s))' % (
             self.context.coll1.__name__,
             self.context.expr1,
             self.context.expr2,

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-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt	2008-08-05 05:48:53 UTC (rev 89358)
@@ -130,7 +130,7 @@
     RunnableQuery:
     reduce(set.union,
     map(lambda i: set([i.name]),
-    set(metadata.getFromIndex("IUnOptimizedClass", "value", 5, 5))), set())
+    set(metadata.getFromIndex("IOptimizedClass", "value", 5, 5))), set())
 
 
 

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/runnablequery.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/runnablequery.py	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/runnablequery.py	2008-08-05 05:48:53 UTC (rev 89358)
@@ -61,7 +61,7 @@
 
     def reanalyze(self):
         optimizedalgebra = IAlgebraOptimizer(self.alg)(self.metadata)
-        runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata, self.alg)
+        runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata, optimizedalgebra)
         return runnable
 
     def execute(self, debug=False):

Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/engine.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/engine.py	2008-08-05 04:42:36 UTC (rev 89357)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/engine.py	2008-08-05 05:48:53 UTC (rev 89358)
@@ -37,10 +37,10 @@
             objectquery = query
         else:
             objectquery = IQueryParser(query)(metadata)
+        
         optimizedoq = IQueryOptimizer(objectquery)()
-
         algebra = IRewriter(optimizedoq)()
         optimizedalgebra = IAlgebraOptimizer(algebra)(metadata)
-        runnable = IAlgebraCompiler(optimizedalgebra)(metadata, algebra)
+        runnable = IAlgebraCompiler(optimizedalgebra)(metadata, optimizedalgebra)
 
-        return runnable
\ No newline at end of file
+        return runnable



More information about the Checkins mailing list