[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ additional modifications to algebra operations to represent how they operate
Charith Paranaliyanage
paranaliyanage at gmail.com
Thu Aug 14 11:57:30 EDT 2008
Log message for revision 89837:
additional modifications to algebra operations to represent how they operate
Changed:
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt
U Sandbox/adamg/ocql/trunk/src/ocql/rewriter/algebra.txt
U Sandbox/adamg/ocql/trunk/src/ocql/rewriter/tests.py
-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py 2008-08-14 14:46:41 UTC (rev 89836)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.py 2008-08-14 15:57:30 UTC (rev 89837)
@@ -83,8 +83,9 @@
compile(self.context.coll1),
compile(self.context.coll2))
elif self.context.klass == list:
- return '(%s)+(%s)' % (
+ return '(%s+filter(lambda x:x not in %s,%s))' % (
compile(self.context.coll1),
+ compile(self.context.coll1),
compile(self.context.coll2))
class DifferCompiler(BaseCompiler):
@@ -98,9 +99,9 @@
compile(self.context.coll2))
elif self.context.klass == list:
- return '(%s)-(%s)' % (
- compile(self.context.coll1),
- compile(self.context.coll2))
+ return '(filter(lambda x:x not in %s,%s))' % (
+ compile(self.context.coll2),
+ compile(self.context.coll1))
class IterCompiler(BaseCompiler):
implements(IAlgebraCompiler)
@@ -139,14 +140,14 @@
def __call__(self):
if self.context.klass == set:
return 'reduce(%s, map(%s, %s), %s)' % (
+ compile(self.context.func),
compile(self.context.aggreg),
- compile(self.context.func),
compile(self.context.coll),
compile(self.context.expr))
elif self.context.klass == list:
return 'reduce(%s, map(%s, %s), %s)'% (
+ compile(self.context.func),
compile(self.context.aggreg),
- compile(self.context.func),
compile(self.context.coll),
compile(self.context.expr))
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt 2008-08-14 14:46:41 UTC (rev 89836)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt 2008-08-14 15:57:30 UTC (rev 89837)
@@ -45,7 +45,7 @@
>>> aopt = AlgebraOptimizer(alg)(metadata)
>>> run = AlgebraCompiler(aopt)(metadata, alg)
>>> print str(run)
- RunnableQuery: ([1])+([2])
+ RunnableQuery: ([1]+filter(lambda x:x not in [1],[2]))
>>> qo = QueryParser("set [ | 1 ] differ set [|2]")(TestMetadata())
>>> opt = QueryOptimizer(qo)()
@@ -61,7 +61,7 @@
>>> aopt = AlgebraOptimizer(alg)(metadata)
>>> run = AlgebraCompiler(aopt)(metadata, alg)
>>> print str(run)
- RunnableQuery: ([1])-([2])
+ RunnableQuery: (filter(lambda x:x not in [2],[1]))
>>> metadata = TestMetadata()
>>> qo = QueryParser("set [ i in ICourse | i ]")(TestMetadata())
Modified: Sandbox/adamg/ocql/trunk/src/ocql/rewriter/algebra.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/rewriter/algebra.txt 2008-08-14 14:46:41 UTC (rev 89836)
+++ Sandbox/adamg/ocql/trunk/src/ocql/rewriter/algebra.txt 2008-08-14 15:57:30 UTC (rev 89837)
@@ -53,7 +53,7 @@
Union(<type 'list'>, [1, 2], [2, 3])
>>> run(x)
- [1, 2, 2, 3]
+ [1, 2, 3]
Differ ( C1, C2 )
@@ -76,8 +76,8 @@
>>> x
Differ(<type 'list'>, [1, 2], [2, 3])
- #>>> run(x)
- #[1]
+ >>> run(x)
+ [1]
Equal ( E1, E2 )
@@ -100,16 +100,15 @@
operand collection C is empty, E0 is returned. When the operand collection
is not empty, F1 is applied to each element of C and the results are supplied
pairwise to Faggregate which accumulates the results to give a single value.
+ >>> import operator
>>> from ocql.rewriter.algebra import Reduce
- >>> from ocql.rewriter.algebra import Lambda
- >>> func = Lambda('y','y+1')
- >>> x = Reduce(set, None, func, func, set([1, 2, 3, 4, 5]))
+ >>> x = Reduce(set, None, 'lambda y, z: y+z', 'operator.add', set([1, 2, 3, 4, 5]))
>>> x
- Reduce(<type 'set'>, None, Lambda y: y+1, Lambda y: y+1, set([1, 2, 3, 4, 5]))
+ Reduce(<type 'set'>, None, lambda y, z: y+z, operator.add, set([1, 2, 3, 4, 5]))
-# >>> run(x)
+ >>> run(x)
+
-
Map ( F, C)
-----------
The map operations apply the operand function F to each element in the operand
@@ -124,17 +123,16 @@
collection.
>>> from ocql.rewriter.algebra import Select
- >>> func = Lambda('z','z%2')
- >>> x = Select(set, func, set([1,2,3]))
+ >>> x = Select(set, 'lambda z: z%2', set([1,2,3]))
>>> x
- Select(<type 'set'>, Lambda z: z%2, set([1, 2, 3]))
+ Select(<type 'set'>, lambda z: z%2, set([1, 2, 3]))
>>> run(x)
set([1, 3])
- >>> x = Select(list, func, [1,2,3])
+ >>> x = Select(list, 'lambda z: z%2', [1,2,3])
>>> x
- Select(<type 'list'>, Lambda z: z%2, [1, 2, 3])
+ Select(<type 'list'>, lambda z: z%2, [1, 2, 3])
>>> run(x)
[1, 3]
Modified: Sandbox/adamg/ocql/trunk/src/ocql/rewriter/tests.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/rewriter/tests.py 2008-08-14 14:46:41 UTC (rev 89836)
+++ Sandbox/adamg/ocql/trunk/src/ocql/rewriter/tests.py 2008-08-14 15:57:30 UTC (rev 89837)
@@ -1,5 +1,6 @@
import unittest
import doctest
+import operator
from zope.testing.doctestunit import DocTestSuite,DocFileSuite
from ocql.testing import utils
More information about the Checkins
mailing list