[Checkins] SVN: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/
fixed problems introduced by latest changes
Adam Groszer
agroszer at gmail.com
Wed Jul 2 06:20:29 EDT 2008
Log message for revision 87919:
fixed problems introduced by latest changes
Changed:
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
U Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/run.txt
U Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/test_old.py
-=-
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-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py 2008-07-02 10:20:29 UTC (rev 87919)
@@ -13,6 +13,7 @@
from zope.component import provideAdapter
from ocql.interfaces import IAlgebraCompiler
+from ocql.interfaces import IAlgebraPartCompiler
from ocql.interfaces import IOptimizedAlgebraObject
#from ocql.interfaces import ICompiledAlgebraObject
@@ -31,7 +32,8 @@
def __call__(self, metadata, algebra):
algebra = self.context
#code = algebra.compile()
- code = IAlgebraCompiler(self.context)()
+ adapter = IAlgebraPartCompiler(self.context)
+ code = adapter()
run = RunnableQuery(metadata, algebra, code)
return run
@@ -41,7 +43,7 @@
self.context = context
class EmptyCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IEmpty)
def __call__(self):
@@ -51,170 +53,181 @@
return '[]'
class SingleCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(ISingle)
def __call__(self):
if self.context.klass == set:
- return 'set(['+IAlgebraCompiler(self.context.expr)()+'])'
+ return 'set(['+IAlgebraPartCompiler(self.context.expr)()+'])'
elif self.context.klass == list:
- return '['+IAlgebraCompiler(self.context.expr)()+']'
+ return '['+IAlgebraPartCompiler(self.context.expr)()+']'
class UnionCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IUnion)
def __call__(self):
if self.context.klass == set:
return 'set.union(%s, %s)' % (
- IAlgebraCompiler(self.context.coll1)(),
- IAlgebraCompiler(self.context.coll2)())
+ IAlgebraPartCompiler(self.context.coll1)(),
+ IAlgebraPartCompiler(self.context.coll2)())
elif self.context.klass == list:
return '(%s)+(%s)' % (
- IAlgebraCompiler(self.context.coll1)(),
- IAlgebraCompiler(self.context.coll2)())
+ IAlgebraPartCompiler(self.context.coll1)(),
+ IAlgebraPartCompiler(self.context.coll2)())
-class IterCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+class IterCompiler(BaseCompiler):
+ implements(IAlgebraPartCompiler)
adapts(IIter)
def __call__(self):
if self.context.func is LambdaCompiler and \
self.context.call 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)())
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.coll)())
if self.context.klass == list:
return 'reduce(operator.add, map(%s, %s), [])' % (
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.coll)())
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(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)())
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.coll)())
if self.context.klass == list:
return 'reduce(operator.add, map(%s, %s), [])' % (
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.coll)())
-
-
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.coll)())
+
+
class SelectCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(ISelect)
def __call__(self):
if self.context.klass == set:
return 'set(filter(%s, %s))' % (
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.call)())
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.call)())
if self.context.klass == list:
return 'filter()%s, %s' % (
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.call)())
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.call)())
class ReduceCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IReduce)
def __call__(self):
if self.context.klass == set:
return 'reduce(%s, map(%s, %s), %s)' % (
- IAlgebraCompiler(self.context.aggreg)(),
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.call)(),
- IAlgebraCompiler(self.context.expr)())
+ IAlgebraPartCompiler(self.context.aggreg)(),
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.coll)(),
+ IAlgebraPartCompiler(self.context.expr)())
elif self.context.klass == list:
return 'reduce(%s, map(%s, %s), %s)'% (
- IAlgebraCompiler(self.context.aggreg)(),
- IAlgebraCompiler(self.context.func)(),
- IAlgebraCompiler(self.context.call)(),
- IAlgebraCompiler(self.context.expr)())
+ IAlgebraPartCompiler(self.context.aggreg)(),
+ IAlgebraPartCompiler(self.context.func)(),
+ IAlgebraPartCompiler(self.context.coll)(),
+ IAlgebraPartCompiler(self.context.expr)())
class RangeCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IRange)
def __call__(self):
if self.context.klass == set:
return 'set(range(%s,%s))' % (
- IAlgebraCompiler(self.context.start)(),
- IAlgebraCompiler(self.context.end)())
+ IAlgebraPartCompiler(self.context.start)(),
+ IAlgebraPartCompiler(self.context.end)())
elif self.context.klass == list:
return 'range(%s,%s)' % (
- IAlgebraCompiler(self.context.start)(),
- IAlgebraCompiler(self.context.end)())
+ IAlgebraPartCompiler(self.context.start)(),
+ IAlgebraPartCompiler(self.context.end)())
class MakeCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IMake)
def __call__(self):
return '%s(metadata.getAll("%s"))' % (
self.context.coll1.__name__,
- IAlgebraCompiler(self.context.expr)())
+ IAlgebraPartCompiler(self.context.expr)())
class IfCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IIf)
def __call__(self):
return '((%s) and (%s) or (%s))' % (
- IAlgebraCompiler(self.context.cond)(),
- IAlgebraCompiler(self.context.expr1)(),
- IAlgebraCompiler(self.context.expr2)())
+ IAlgebraPartCompiler(self.context.cond)(),
+ IAlgebraPartCompiler(self.context.expr1)(),
+ IAlgebraPartCompiler(self.context.expr2)())
class LambdaCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(ILambda)
def __call__(self):
return 'lambda %s: %s'%(
self.context.var,
- IAlgebraCompiler(self.context.expr)())
+ IAlgebraPartCompiler(self.context.expr)())
class ConstantCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IConstant)
def __call__(self):
return '%s'% (self.context.value)
-
+
class IdentifierCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IIdentifier)
def __call__(self):
return self.context.name
-class BineryCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
- adapts(IBinery)
+class BinaryCompiler(BaseCompiler):
+ implements(IAlgebraPartCompiler)
+ adapts(IBinary)
def __call__(self):
return '%s%s%s' % (
- IAlgebraCompiler(self.context.left)(),
- IAlgebraCompiler(self.context.op.op)(),
- IAlgebraCompiler(self.context.right)())
+ IAlgebraPartCompiler(self.context.left)(),
+ self.context.op.op,
+ IAlgebraPartCompiler(self.context.right)())
class OperatorCompiler(BaseCompiler):
- implements(IAlgebraCompiler)
+ implements(IAlgebraPartCompiler)
adapts(IOperator)
+ ops = {
+ 'or': 'operator.or_',
+ 'and': 'operator.and_',
+ 'not': 'operator.not_',
+ '+': 'operator.add', '-': 'operator.sub',
+ '*': 'operator.mul', '/': 'operator.div',
+ '<': 'operator.lt', '>': 'operator.gt',
+ '<=': 'operator.le', '>=': 'operator.ge',
+ '==': 'operator.eq', '~=': 'operator.ne',
+ }
+
def __call__(self):
- return self.context.ops[self.context.op]
+ return self.ops[self.context.op]
def registerAdapters():
@@ -230,6 +243,5 @@
provideAdapter(LambdaCompiler)
provideAdapter(ConstantCompiler)
provideAdapter(IdentifierCompiler)
- provideAdapter(BineryCompiler)
+ provideAdapter(BinaryCompiler)
provideAdapter(OperatorCompiler)
-
\ No newline at end of file
Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py 2008-07-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/interfaces.py 2008-07-02 10:20:29 UTC (rev 87919)
@@ -44,6 +44,10 @@
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.
@@ -75,7 +79,7 @@
"""
def compile(self):
"""Return the compiled python code"""
-
+
def walk(self):
"""Iterate the Algebra object tree"""
@@ -115,4 +119,3 @@
"""Stores statistical data based on queries run before.
Provides statistical data for optimization.
"""
-
\ No newline at end of file
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-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/algebra.py 2008-07-02 10:20:29 UTC (rev 87919)
@@ -30,9 +30,9 @@
pass
class Empty(BaseAlgebra):
-
+
implements(IEmpty)
-
+
def __init__(self, klass, expr):
self.klass = klass
@@ -45,7 +45,7 @@
class Single(BaseAlgebra):
implements(ISingle)
-
+
def __init__(self, klass, expr):
self.klass = klass
self.expr = expr
@@ -59,9 +59,9 @@
yield t
class Union(BaseAlgebra):
-
+
implements(IUnion)
-
+
def __init__(self, klass, coll1, coll2):
self.klass=klass
self.coll1=coll1
@@ -91,9 +91,9 @@
class Iter(BaseAlgebra):
-
+
implements(IIter)
-
+
def __init__(self, klass, func, coll):
self.klass = klass
self.func = func
@@ -110,9 +110,9 @@
yield t
class Select(BaseAlgebra):
-
+
implements(ISelect)
-
+
def __init__(self, klass, func, coll):
self.klass = klass
self.func = func
@@ -129,9 +129,9 @@
yield t
class Reduce(BaseAlgebra):
-
+
implements(IReduce)
-
+
def __init__(self, klass, expr, func, aggreg, coll):
self.klass = klass
self.expr = expr
@@ -166,9 +166,9 @@
# return 'filter(%s,%s)' % (self.coll1.compile(),self.coll2.compile())
#
class Range(BaseAlgebra):
-
+
implements(IRange)
-
+
def __init__(self, klass, start, enf):
self.klass = klass
self.start = start
@@ -185,9 +185,9 @@
#class Index
class Make(BaseAlgebra):
-
+
implements(IMake)
-
+
def __init__(self, coll1, coll2, expr):
self.expr = expr
self.coll1 = coll1
@@ -205,9 +205,9 @@
#class Being:
class If(BaseAlgebra):
-
+
implements(IIf)
-
+
def __init__(self, cond, expr1, expr2):
self.cond = cond
self.expr1 = expr1
@@ -229,9 +229,9 @@
#
#
class Lambda(BaseAlgebra):
-
+
implements(ILambda)
-
+
def __init__(self, var, expr):
self.var = var
self.expr = expr
@@ -245,9 +245,9 @@
yield t
class Constant(BaseAlgebra):
-
+
implements(IConstant)
-
+
def __init__(self, value):
self.value = value
@@ -258,9 +258,9 @@
yield self
class Identifier(BaseAlgebra):
-
+
implements(IIdentifier)
-
+
def __init__(self, name):
self.name=name
@@ -271,9 +271,9 @@
yield self
class Binary(BaseAlgebra):
-
- implements(IBinery)
-
+
+ implements(IBinary)
+
def __init__(self, left, op, right):
self.left = left
self.op = op
@@ -290,19 +290,9 @@
yield t
class Operator(BaseAlgebra):
-
+
implements(IOperator)
-
- ops = {
- 'or': 'operator.or_',
- 'and': 'operator.and_',
- 'not': 'operator.not_',
- '+': 'operator.add', '-': 'operator.sub',
- '*': 'operator.mul', '/': 'operator.div',
- '<': 'operator.lt', '>': 'operator.gt',
- '<=': 'operator.le', '>=': 'operator.ge',
- '==': 'operator.eq', '~=': 'operator.ne',
- }
+
def __init__(self, op):
self.op = op
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-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/rewriter/interfaces.py 2008-07-02 10:20:29 UTC (rev 87919)
@@ -11,7 +11,7 @@
class IEmpty(IAlgebraObject):
"""Objects providing this interface represent the
Empty Algebra object
- """
+ """
klass = Attribute('collection type name')
expr = Attribute('expression')
@@ -23,7 +23,7 @@
klass = Attribute('collection type name')
expr = Attribute('expression')
-
+
class IUnion(IAlgebraObject):
"""Objects providing this interface represent the
Union Algebra object
@@ -32,7 +32,7 @@
coll1 = Attribute('first collection')
coll2 = Attribute('second collection')
-
+
class IIter(IAlgebraObject):
"""Objects providing this interface represent the
Iter Algebra object
@@ -40,8 +40,8 @@
klass = Attribute('collection type name')
fun = Attribute('function')
coll = Attribute('collection')
-
+
class ISelect(IAlgebraObject):
"""Objects providing this interface represent the
Select Algebra object
@@ -49,8 +49,8 @@
klass = Attribute('collection type name')
fun = Attribute('function')
coll = Attribute('collection')
-
+
class IReduce(IAlgebraObject):
"""Objects providing this interface represent the
Reduce Algebra object
@@ -60,8 +60,8 @@
fun = Attribute('function')
aggreg = Attribute('aggregation')
coll = Attribute('collection')
-
-
+
+
class IRange(IAlgebraObject):
"""Objects providing this interface represent the
Range Algebra object
@@ -70,7 +70,7 @@
start = Attribute('range start point')
end = Attribute('range end point')
-
+
class IMake(IAlgebraObject):
"""Objects providing this interface represent the
Make Algebra object
@@ -79,7 +79,7 @@
coll1 = Attribute('first collection')
coll2 = Attribute('second collection')
-
+
class IIf(IAlgebraObject):
"""Objects providing this interface represent the
If Algebra object
@@ -88,7 +88,7 @@
expr1 = Attribute('first expression')
expr2 =Attribute('second expression')
-
+
class ILambda(IAlgebraObject):
"""Objects providing this interface represent the
Lambda Algebra object
@@ -109,9 +109,9 @@
Identifier Algebra object
"""
name = Text()
-
-
-class IBinery(IAlgebraObject):
+
+
+class IBinary(IAlgebraObject):
"""Objects providing this interface represent the
Binery Algebra object
"""
Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/run.txt
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/run.txt 2008-07-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/run.txt 2008-07-02 10:20:29 UTC (rev 87919)
@@ -19,7 +19,10 @@
>>> from ocql.engine import OCQLEngine
+ >>> from ocql.compiler.compiler import registerAdapters
+ >>> registerAdapters()
+
>>> engine = OCQLEngine()
>>> run = engine.compile("set [ | 1 ]")
>>> run
@@ -37,7 +40,7 @@
>>> engine = OCQLEngine()
>>> run = engine.compile("set [ | 1 ] union set [|2]")
>>> run
- RunnableQuery: set.union(set([1]),set([2]))
+ RunnableQuery: set.union(set([1]), set([2]))
>>> result = run.execute()
>>> result
@@ -51,7 +54,7 @@
>>> engine = OCQLEngine()
>>> run = engine.compile("set [ i in ICourse | i ]")
>>> run
- RunnableQuery: reduce(set.union, map(lambda i: set([i]),set(metadata.getAll("ICourse"))) , set())
+ RunnableQuery: reduce(set.union, map(lambda i: set([i]),set(metadata.getAll("ICourse"))), set())
>>> result = run.execute()
>>> result
@@ -65,7 +68,7 @@
>>> engine = OCQLEngine()
>>> run = engine.compile("set [ c in ICourse | c.code ]")
>>> run
- RunnableQuery: reduce(set.union, map(lambda c: set([c.code]),set(metadata.getAll("ICourse"))) , set())
+ RunnableQuery: reduce(set.union, map(lambda c: set([c.code]),set(metadata.getAll("ICourse"))), set())
>>> result = run.execute()
>>> result
Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/test_old.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/test_old.py 2008-07-02 09:27:20 UTC (rev 87918)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/tests/test_old.py 2008-07-02 10:20:29 UTC (rev 87919)
@@ -26,6 +26,8 @@
from ocql.compiler.compiler import AlgebraCompiler
from ocql.testing.database import TestMetadata
+from ocql.compiler.compiler import registerAdapters
+
from ocql.testing.database import C1, C2, C3
from ocql.testing.database import D1, D2, D3
@@ -55,6 +57,7 @@
provideAdapter(AlgebraOptimizer)
provideAdapter(AlgebraCompiler)
provideAdapter(TestMetadata)
+ registerAdapters()
self.engine = OCQLEngine()
More information about the Checkins
mailing list