[Checkins] SVN: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/
add tests and small modifications for the mistakes identified
by tests
Charith Paranaliyanage
paranaliyanage at gmail.com
Sun Aug 3 15:15:41 EDT 2008
Log message for revision 89309:
add tests and small modifications for the mistakes identified by tests
Changed:
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/compiler/compiler.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/parser/newqueryparser.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.txt
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.txt
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/interfaces.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.txt
-=-
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/compiler/compiler.py 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/compiler/compiler.py 2008-08-03 19:15:41 UTC (rev 89309)
@@ -84,13 +84,13 @@
def __call__(self):
if self.context.klass == set:
return 'set.differ(%s, %s)' % (
- IAlgebraCompiler(self.context.start)(),
- IAlgebraCompiler(self.context.end)())
+ IAlgebraCompiler(self.context.coll1)(),
+ IAlgebraCompiler(self.context.coll2)())
elif self.context.klass == list:
return '(%s)-(%s)' % (
- IAlgebraCompiler(self.context.start)(),
- IAlgebraCompiler(self.context.end)())
+ IAlgebraCompiler(self.context.coll1)(),
+ IAlgebraCompiler(self.context.coll2)())
class IterCompiler(BaseCompiler):
implements(IAlgebraCompiler)
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/parser/newqueryparser.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/parser/newqueryparser.py 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/parser/newqueryparser.py 2008-08-03 19:15:41 UTC (rev 89309)
@@ -642,7 +642,7 @@
implements(IQueryParser)
adapts(basestring)
registerAdapters()
-# import pydevd;pydevd.settrace()
+
def __init__(self, context):
self.context = context
#self.db = db
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.txt
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.txt 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.txt 2008-08-03 19:15:41 UTC (rev 89309)
@@ -8,128 +8,221 @@
>>> from ocql.queryobject.interfaces import *
>>> from ocql.queryobject.queryobject import *
+ >>> from ocql.testing.database import TestMetadata
+ >>> from ocql.parser.newqueryparser import SymbolContainer
>>> from zope.interface.verify import verifyClass, verifyObject
+ >>> child = Child()
+ >>> metadata = TestMetadata()
+ >>> symbols = SymbolContainer()
+
>>> verifyClass(IObjectQueryHead, Head)
True
+ >>> verifyObject(IObjectQueryHead, Head(child))
+ True
>>> verifyClass(IObjectQueryChild, Child)
True
+ >>> verifyObject(IObjectQueryChild, child)
+ True
>>> verifyClass(IObjectQuery, QueryObject)
True
+ >>> verifyObject(IObjectQuery, QueryObject(metadata, symbols))
+ True
>>> verifyClass(ITerm, Term)
True
+ >>> verifyObject(ITerm, Term(metadata, symbols, child, child))
+ True
>>> verifyClass(IExpression, Expression)
True
+ >>> verifyObject(IExpression, Expression(metadata, symbols, child, child))
+ True
>>> verifyClass(IhasClassWith, hasClassWith)
True
+ >>> verifyObject(IhasClassWith, hasClassWith(metadata, symbols, child, set, child))
+ True
>>> verifyClass(IIdentifier, Identifier)
True
+ >>> verifyObject(IIdentifier, Identifier(metadata, symbols, child))
+ True
>>> verifyClass(IConstant, Constant)
True
+ >>> verifyObject(IConstant, Constant(metadata, symbols, child))
+ True
>>> verifyClass(IQuery, Query)
True
+ >>> verifyObject(IQuery, Query(metadata, symbols, set, [child], child))
+ True
+ >>> verifyClass(IIn, In)
+ True
+ >>> verifyObject(IIn, In(metadata, symbols, child, child))
+ True
+
>>> verifyClass(IAlias, Alias)
True
+ >>> verifyObject(IAlias, Alias(metadata, symbols, child, child))
+ True
>>> verifyClass(IBinary, Binary)
True
+ >>> verifyObject(IBinary, Binary(metadata, symbols, child, child))
+ True
>>> verifyClass(IUnion, Union)
True
+ >>> verifyObject(IUnion, Union(metadata, symbols, child, child))
+ True
>>> verifyClass(IDiffer, Differ)
True
+ >>> verifyObject(IDiffer, Differ(metadata, symbols, child, child))
+ True
>>> verifyClass(IAnd, And)
True
+ >>> verifyObject(IAnd, And(metadata, symbols, child, child))
+ True
>>> verifyClass(IOr, Or)
True
+ >>> verifyObject(IOr, Or(metadata, symbols, child, child))
+ True
>>> verifyClass(IProperty, Property)
True
+ >>> verifyObject(IProperty, Property(metadata, symbols, child, child))
+ True
>>> verifyClass(IIndex, Index)
True
+ >>> verifyObject(IIndex, Index(metadata, symbols, child, child))
+ True
>>> verifyClass(IArithmetic, Arithmetic)
True
+ >>> verifyObject(IArithmetic, Arithmetic(metadata, symbols, child, child))
+ True
>>> verifyClass(IAdd, Add)
True
+ >>> verifyObject(IAdd, Add(metadata, symbols, child, child))
+ True
>>> verifyClass(IMul, Mul)
True
+ >>> verifyObject(IMul, Mul(metadata, symbols, child, child))
+ True
>>> verifyClass(ISub, Sub)
True
+ >>> verifyObject(ISub, Sub(metadata, symbols, child, child))
+ True
>>> verifyClass(IDiv, Div)
True
+ >>> verifyObject(IDiv, Div(metadata, symbols, child, child))
+ True
>>> verifyClass(IUnary, Unary)
True
+ >>> verifyObject(IUnary, Unary(metadata, symbols, child))
+ True
>>> verifyClass(INot, Not)
True
+ >>> verifyObject(INot , Not(metadata, symbols, child))
+ True
>>> verifyClass(IAggregate, Aggregate)
True
+ >>> verifyObject(IAggregate, Aggregate(metadata, symbols, child))
+ True
>>> verifyClass(ICount, Count)
True
+ >>> verifyObject(ICount, Count(metadata, symbols, child))
+ True
>>> verifyClass(ISum, Sum)
True
+ >>> verifyObject(ISum, Sum(metadata, symbols, child))
+ True
>>> verifyClass(IQuantor, Quantor)
True
+ >>> verifyObject(IQuantor, Quantor(metadata, symbols, child))
+ True
>>> verifyClass(IQuanted, Quanted)
True
+ >>> verifyObject(IQuanted, Quanted(metadata, symbols, child, child))
+ True
>>> verifyClass(IEvery, Every)
True
+ >>> verifyObject(IEvery, Every(metadata, symbols, child))
+ True
>>> verifyClass(ISome, Some)
True
+ >>> verifyObject(ISome, Some(metadata, symbols, child))
+ True
>>> verifyClass(IAtmost, Atmost)
True
+ >>> verifyObject(IAtmost, Atmost(metadata, symbols, child))
+ True
>>> verifyClass(IAtleast, Atleast)
True
+ >>> verifyObject(IAtleast, Atleast(metadata, symbols, child))
+ True
>>> verifyClass(IJust, Just)
True
+ >>> verifyObject(IJust, Just(metadata, symbols, child))
+ True
>>> verifyClass(ICondition, Condition)
True
+ >>> verifyObject(ICondition, Condition(metadata, symbols, child, child))
+ True
>>> verifyClass(IEq, Eq)
True
+ >>> verifyObject(IEq, Eq(metadata, symbols, child, child))
+ True
>>> verifyClass(INe, Ne)
True
+ >>> verifyObject(INe, Ne(metadata, symbols, child, child))
+ True
>>> verifyClass(ILt, Lt)
True
+ >>> verifyObject(ILt, Lt(metadata, symbols, child, child))
+ True
>>> verifyClass(IGt, Gt)
True
+ >>> verifyObject(IGt, Gt(metadata, symbols, child, child))
+ True
>>> verifyClass(ILe, Le)
True
+ >>> verifyObject(ILe, Le(metadata, symbols, child, child))
+ True
>>> verifyClass(IGe, Ge)
True
+ >>> verifyObject(IGe, Ge(metadata, symbols, child, child))
+ True
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.py 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.py 2008-08-03 19:15:41 UTC (rev 89309)
@@ -44,7 +44,7 @@
class Empty(BaseAlgebra):
implements(IEmpty)
- def __init__(self, klass, expr):
+ def __init__(self, klass):
self.klass = klass
def __repr__(self):
@@ -76,16 +76,19 @@
def __repr__(self):
return 'Union(%s,%s,%s)'%(self.klass, self.coll1, self.coll2)
-class Differ:
+class Differ(BaseAlgebra):
implements(IDiffer)
- def __init__(self, klass, start, end):
+ def __init__(self, klass, coll1, coll2):
self.klass = klass
- self.start = start
- self.end = end
+ self.coll1 = coll1
+ self.coll2 = coll2
+ locate(coll1, self, 'coll1')
+ locate(coll2, self, 'coll2')
+ self.children.extend([coll1, coll2])
def __repr__(self):
- return 'Differ(%s,%s,%s)'%(self.klass, self.start, self.end)
+ return 'Differ(%s,%s,%s)'%(self.klass, self.coll1, self.coll2)
class Iter(BaseAlgebra):
implements(IIter)
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.txt
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.txt 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/algebra.txt 2008-08-03 19:15:41 UTC (rev 89309)
@@ -13,49 +13,92 @@
>>> verifyClass(IAlgebraObjectHead, Head)
True
+ >>> baseAlgebra = BaseAlgebra()
+ >>> verifyObject(IAlgebraObjectHead, Head(baseAlgebra))
+ True
>>> verifyClass(IAlgebraObject, BaseAlgebra)
True
+ >>> verifyObject(IAlgebraObject, baseAlgebra)
+ True
>>> verifyClass(IEmpty, Empty)
True
+ >>> verifyObject(IEmpty, Empty(set))
+ True
>>> verifyClass(ISingle, Single)
True
+ >>> verifyObject(ISingle, Single(set, baseAlgebra))
+ True
>>> verifyClass(IUnion, Union)
True
+ >>> verifyObject(IUnion, Union(set, baseAlgebra, baseAlgebra))
+ True
+ >>> verifyClass(IDiffer, Differ)
+ True
+ >>> verifyObject(IDiffer, Differ(set, baseAlgebra, baseAlgebra))
+ True
+
>>> verifyClass(IIter, Iter)
True
+ >>> verifyObject(IIter, Iter(set, baseAlgebra, baseAlgebra))
+ True
+ >>> verifyClass(ISelect, Select)
+ True
+ >>> verifyObject(ISelect, Select(set, baseAlgebra, baseAlgebra))
+ True
+
>>> verifyClass(IReduce, Reduce)
True
+ >>> verifyObject(IReduce, Reduce(set, baseAlgebra, baseAlgebra, baseAlgebra, baseAlgebra))
+ True
>>> verifyClass(IRange, Range)
True
+ >>> verifyObject(IRange, Range(set, baseAlgebra, baseAlgebra))
+ True
>>> verifyClass(IMake, Make)
True
+ >>> verifyObject(IMake, Make(baseAlgebra, baseAlgebra, baseAlgebra))
+ True
#Uncomment this after merge other branch modifications
#>>> verifyClass(IMakeFromIndex, MakeFromIndex)
#True
+ #>>> verifyObject(IMakeFromIndex, MakeFromIndex(baseAlgebra, baseAlgebra, baseAlgebra, baseAlgebra))
+ #True
>>> verifyClass(IIf, If)
True
+ >>> verifyObject(IIf, If(baseAlgebra, baseAlgebra, baseAlgebra))
+ True
>>> verifyClass(ILambda, Lambda)
True
+ >>> verifyObject(ILambda, Lambda(baseAlgebra, baseAlgebra))
+ True
>>> verifyClass(IConstant, Constant)
True
+ >>> verifyObject(IConstant, Constant(baseAlgebra))
+ True
>>> verifyClass(IIdentifier, Identifier)
True
+ >>> verifyObject(IIdentifier, Identifier(baseAlgebra))
+ True
>>> verifyClass(IBinary, Binary)
True
+ >>> verifyObject(IBinary, Binary(baseAlgebra, baseAlgebra, baseAlgebra))
+ True
>>> verifyClass(IOperator, Operator)
True
+ >>> verifyObject(IOperator, Operator(baseAlgebra))
+ True
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/interfaces.py 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/interfaces.py 2008-08-03 19:15:41 UTC (rev 89309)
@@ -13,9 +13,7 @@
Empty Algebra object
"""
klass = Attribute('collection type name')
- expr = Attribute('expression')
-
class ISingle(IAlgebraObject):
"""Objects providing this interface represent the
Single Algebra object
@@ -23,7 +21,6 @@
klass = Attribute('collection type name')
expr = Attribute('expression')
-
class IUnion(IAlgebraObject):
"""Objects providing this interface represent the
Union Algebra object
@@ -37,38 +34,35 @@
Union Algebra object
"""
klass = Attribute('collection type name')
- start = Attribute('first collection')
- end = Attribute('second collection')
+ coll1 = Attribute('first collection')
+ coll2 = Attribute('second collection')
class IIter(IAlgebraObject):
"""Objects providing this interface represent the
Iter Algebra object
"""
klass = Attribute('collection type name')
- fun = Attribute('function')
+ func = Attribute('function')
coll = Attribute('collection')
-
class ISelect(IAlgebraObject):
"""Objects providing this interface represent the
Select Algebra object
"""
klass = Attribute('collection type name')
- fun = Attribute('function')
+ func = Attribute('function')
coll = Attribute('collection')
-
class IReduce(IAlgebraObject):
"""Objects providing this interface represent the
Reduce Algebra object
"""
klass = Attribute('collection type name')
expr = Attribute('expression')
- fun = Attribute('function')
+ func = Attribute('function')
aggreg = Attribute('aggregation')
coll = Attribute('collection')
-
class IRange(IAlgebraObject):
"""Objects providing this interface represent the
Range Algebra object
@@ -77,7 +71,6 @@
start = Attribute('range start point')
end = Attribute('range end point')
-
class IMake(IAlgebraObject):
"""Objects providing this interface represent the
Make Algebra object
@@ -86,7 +79,6 @@
coll1 = Attribute('first collection')
coll2 = Attribute('second collection')
-
class IIf(IAlgebraObject):
"""Objects providing this interface represent the
If Algebra object
@@ -95,7 +87,6 @@
expr1 = Attribute('first expression')
expr2 =Attribute('second expression')
-
class ILambda(IAlgebraObject):
"""Objects providing this interface represent the
Lambda Algebra object
@@ -103,21 +94,18 @@
var = Attribute('variable')
expr = Attribute('expression')
-
class IConstant(IAlgebraObject):
"""Objects providing this interface represent the
Constant Algebra object
"""
value = Attribute('constant value')
-
class IIdentifier(IAlgebraObject):
"""Objects providing this interface represent the
Identifier Algebra object
"""
name = Text()
-
class IBinary(IAlgebraObject):
"""Objects providing this interface represent the
Binery Algebra object
@@ -126,10 +114,9 @@
op = Attribute('operator')
right = Attribute('right expression')
-
class IOperator(IAlgebraObject):
"""Objects providing this interface represent the
Operator Algebra object
"""
- ops = Dict(Text(), Text())
+# ops = Dict(Text(), Text())
op = Text()
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.py 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.py 2008-08-03 19:15:41 UTC (rev 89309)
@@ -107,7 +107,7 @@
self.context.collection_type,
self.context.terms[1:],
self.context.target))(),
- Empty(self.context.collection_type, None)
+ Empty(self.context.collection_type)
)
else:
rv = Single(
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.txt
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.txt 2008-08-03 19:13:46 UTC (rev 89308)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/rewriter/rewriter.txt 2008-08-03 19:15:41 UTC (rev 89309)
@@ -19,6 +19,11 @@
>>> print str(alg)
Single(<type 'set'>,`1`)
+ >>> qo = QueryParser("list [ | 1 ]")(TestMetadata())
+ >>> opt = QueryOptimizer(qo)()
+ >>> alg = Rewriter(opt)()
+ >>> print str(alg)
+ Single(<type 'list'>,`1`)
>>> qo = QueryParser("set [ | 1 ] union set [|2]")(TestMetadata())
>>> opt = QueryOptimizer(qo)()
@@ -26,14 +31,23 @@
>>> print str(alg)
Union(<type 'set'>,Single(<type 'set'>,`1`),Single(<type 'set'>,`2`))
+ >>> qo = QueryParser("list [ | 1 ] union list [|2]")(TestMetadata())
+ >>> opt = QueryOptimizer(qo)()
+ >>> alg = Rewriter(opt)()
+ >>> print str(alg)
+ Union(<type 'list'>,Single(<type 'list'>,`1`),Single(<type 'list'>,`2`))
- #Differ not implemented
- #>>> qo = QueryParser("set [ | 1 ] differ set [|2]")(TestMetadata())
- #>>> opt = QueryOptimizer(qo)()
- #>>> alg = Rewriter(opt)()
- #>>> print str(alg)
- #Union(<type 'set'>,Single(<type 'set'>,`1`),Single(<type 'set'>,`2`))
+ >>> qo = QueryParser("set [ | 1 ] differ set [|2]")(TestMetadata())
+ >>> opt = QueryOptimizer(qo)()
+ >>> alg = Rewriter(opt)()
+ >>> print str(alg)
+ Differ(<type 'set'>,Single(<type 'set'>,`1`),Single(<type 'set'>,`2`))
+ >>> qo = QueryParser("list [ | 1 ] differ list [|2]")(TestMetadata())
+ >>> opt = QueryOptimizer(qo)()
+ >>> alg = Rewriter(opt)()
+ >>> print str(alg)
+ Differ(<type 'list'>,Single(<type 'list'>,`1`),Single(<type 'list'>,`2`))
>>> qo = QueryParser("set [ i in ICourse | i ]")(TestMetadata())
>>> opt = QueryOptimizer(qo)()
@@ -41,6 +55,11 @@
>>> print str(alg)
Iter(<type 'set'>,Lambda i: Single(<type 'set'>,i),Make(<type 'set'>,<type 'set'>,ICourse))
+# >>> qo = QueryParser("list [ i in ICourse | i ]")(TestMetadata())
+# >>> opt = QueryOptimizer(qo)()
+# >>> alg = Rewriter(opt)()
+# >>> print str(alg)
+# Iter(<type 'list'>,Lambda i: Single(<type 'list'>,i),Make(<type 'list'>,<type 'list'>,ICourse))
#bag not implemented
#>>> qo = QueryParser("size set [ i in ICourse | i ]")(TestMetadata())
More information about the Checkins
mailing list