[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ move opimization checking tests from test_zope to aoptimizer_all.txt and compiler_optimized.txt
Charith Paranaliyanage
paranaliyanage at gmail.com
Fri Aug 29 11:24:26 EDT 2008
Log message for revision 90598:
move opimization checking tests from test_zope to aoptimizer_all.txt and compiler_optimized.txt
Changed:
U Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer_all.txt
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt
A Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized_testdata.txt
U Sandbox/adamg/ocql/trunk/src/ocql/compiler/tests.py
U Sandbox/adamg/ocql/trunk/src/ocql/testing/utils_opt.py
U Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py
-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer_all.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer_all.txt 2008-08-29 15:06:41 UTC (rev 90597)
+++ Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer_all.txt 2008-08-29 15:24:25 UTC (rev 90598)
@@ -17,14 +17,19 @@
>>> from ocql.rewriter.rewriter import Rewriter
>>> from ocql.compiler.compiler import AlgebraCompiler
- >>> from ocql.testing.utils_opt import setupInterfaces
- >>> setupInterfaces(None)
- >>> from ocql.testing.utils_opt import setupCatalog
- >>> setupCatalog(None)
+ >>> import ocql.testing.utils_opt
+ >>> ocql.testing.utils_opt.setupInterfaces(None)
+ >>> ocql.testing.utils_opt.setupCatalog(None)
+ >>> import ocql.testing.utils
+ >>> ocql.testing.utils.setupInterfaces(None)
+ >>> ocql.testing.utils.setupCatalog(None)
+
>>> testmeta = IDB(None)
+
Here is a very basic query to show how the algebra looks like unoptimized.
+--------------------------------------------------------------------------
>>> query = "set [ i in IUnOptimizedClass | i ]"
@@ -46,3 +51,120 @@
Lambda i: Single(<type 'set'>, i),
Make(<type 'set'>, <type 'set'>, IUnOptimizedClass)))
+
+
+Queries using test data to show how the algebra looks like unoptimized.
+-----------------------------------------------------------------------
+
+ >>> query = "set [ c in IStudent; c.country == 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country == `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, ==, 'USA')))
+
+
+ >>> query = "set [ c in IStudent; c.country != 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country != `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, !=, 'USA')))
+
+
+ >>> query = "set [ c in IStudent; c.country <= 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country <= `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, <=, 'USA')))
+
+
+ >>> query = "set [ c in IStudent; c.country >= 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country >= `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, >=, 'USA')))
+
+
+ >>> query = "set [ c in IStudent; c.country < 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country < `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, <, 'USA')))
+
+
+ >>> query = "set [ c in IStudent; c.country > 'USA' | c.name ]"
+ >>> optqo = QueryOptimizer(QueryParser(query)(testmeta))()
+ >>> alg = Rewriter(optqo)()
+ >>> algopt = AlgebraOptimizer(alg)(testmeta)
+
+unoptimized algebra tree
+ >>> alg
+ Head(Iter(<type 'set'>,
+ Lambda c:
+ If(c.country > `'USA'`, Single(<type 'set'>, c.name), Empty(<type 'set'>)),
+ Make(<type 'set'>, <type 'set'>, IStudent)))
+
+optimized algebra tree
+ >>> algopt
+ Head(Iter(<type 'set'>,
+ Lambda c: Single(<type 'set'>, c.name),
+ MakeFromIndex(<type 'set'>, <type 'set'>, IStudent, country, >, 'USA')))
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt 2008-08-29 15:06:41 UTC (rev 90597)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt 2008-08-29 15:24:25 UTC (rev 90598)
@@ -22,12 +22,7 @@
>>> import ocql.testing.utils_opt
>>> ocql.testing.utils_opt.setupInterfaces(None)
- >>> import ocql.testing.utils
- >>> ocql.testing.utils.setupInterfaces(None)
- >>> import ocql.testing.utils_opt
>>> ocql.testing.utils_opt.setupCatalog(None)
- >>> import ocql.testing.utils_opt
- >>> ocql.testing.utils.setupCatalog(None)
We'll use the same queries as in aoptimizer.txt.
Algebra trees get omitted as they are already checked over there.
@@ -128,16 +123,3 @@
>>> result = run.execute()
>>> sorted(result)
[u'0', u'1', u'2', u'3', u'4', u'6', u'7', u'8', u'9']
-
-
-
- >>> query = "set [ c in IStudent; c.country == 'USA' | c.name ]"
- >>> run = OCQLEngine().compile(query)
- >>> run
- RunnableQuery:
- reduce(set.union,
- map(lambda c: set([c.name]),
- set(metadata.getFromIndex("IStudent", "country", "==", 'USA'))), set())
- >>> result = run.execute()
- >>> result
- set([u'Jane'])
Added: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized_testdata.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized_testdata.txt (rev 0)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized_testdata.txt 2008-08-29 15:24:25 UTC (rev 90598)
@@ -0,0 +1,92 @@
+
+Optimized compilation
+=====================
+
+Checking here how an optimized algebra for zope indexes compiles into python code.
+Also refer the compiler_optimized.txt
+
+We need some imports and setup:
+
+ >>> from ocql.engine import OCQLEngine
+
+ >>> import ocql.testing.utils
+ >>> ocql.testing.utils.setupInterfaces(None)
+ >>> ocql.testing.utils.setupCatalog(None)
+
+ >>> query = "set [ c in IStudent; c.country == 'USA' | c.name ]"
+ >>> run = OCQLEngine().compile(query)
+
+Here is the runnable code:
+It uses metadata.getFromIndex as there is an index for the class and property.
+
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", "==", 'USA'))), set())
+
+Results of the query:
+
+ >>> result = run.execute()
+ >>> result
+ set([u'Jane'])
+
+
+ >>> query = "set [c in IStudent; c.country != 'USA' | c.name]"
+ >>> run = OCQLEngine().compile(query)
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", "!=", 'USA'))), set())
+ >>> result = run.execute()
+ >>> result
+ set([u'Ann', u'Charith', u'Stewart'])
+
+
+ >>> query = "set [ c in IStudent; c.country <= 'USA' | c.name ]"
+ >>> run = OCQLEngine().compile(query)
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", "<=", 'USA'))), set())
+ >>> result = run.execute()
+ >>> result
+ set([u'Jane', u'Ann', u'Charith', u'Stewart'])
+
+
+ >>> query = "set [ c in IStudent; c.country >= 'USA' | c.name ]"
+ >>> run = OCQLEngine().compile(query)
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", ">=", 'USA'))), set())
+ >>> result = run.execute()
+ >>> result
+ set([u'Jane'])
+
+
+ >>> query = "set [ c in IStudent; c.country < 'USA' | c.name ]"
+ >>> run = OCQLEngine().compile(query)
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", "<", 'USA'))), set())
+ >>> result = run.execute()
+ >>> result
+ set([u'Ann', u'Charith', u'Stewart'])
+
+
+ >>> query = "set [ c in IStudent; c.country > 'USA' | c.name ]"
+ >>> run = OCQLEngine().compile(query)
+ >>> run
+ RunnableQuery:
+ reduce(set.union,
+ map(lambda c: set([c.name]),
+ set(metadata.getFromIndex("IStudent", "country", ">", 'USA'))), set())
+ >>> result = run.execute()
+ >>> result
+ set([])
Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/tests.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/tests.py 2008-08-29 15:06:41 UTC (rev 90597)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/tests.py 2008-08-29 15:24:25 UTC (rev 90598)
@@ -13,6 +13,9 @@
DocFileSuite('compiler_optimized.txt',
optionflags=flags,
setUp = utils.setupAdapters),
+ DocFileSuite('compiler_optimized_testdata.txt',
+ optionflags=flags,
+ setUp = utils.setupAdapters),
DocFileSuite('debug.txt',
optionflags=flags,
setUp = utils.setupAdapters),
Modified: Sandbox/adamg/ocql/trunk/src/ocql/testing/utils_opt.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/testing/utils_opt.py 2008-08-29 15:06:41 UTC (rev 90597)
+++ Sandbox/adamg/ocql/trunk/src/ocql/testing/utils_opt.py 2008-08-29 15:24:25 UTC (rev 90598)
@@ -120,4 +120,4 @@
id = intids.register(o)
cat.index_doc(id, o)
- component.provideUtility(cat, ICatalog, name='boo-catalog')
+ component.provideUtility(cat, ICatalog, name='foo-catalog')
Modified: Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py 2008-08-29 15:06:41 UTC (rev 90597)
+++ Sandbox/adamg/ocql/trunk/src/ocql/tests/test_zope.py 2008-08-29 15:24:25 UTC (rev 90598)
@@ -210,7 +210,7 @@
#
# set [ c in IStudent; c.country <= "Sri Lanka" | c.name]
#
- query = "[c in IStudent; c.country <= 'Sri Lanka' | c.name]"
+ query = "set [c in IStudent; c.country <= 'Sri Lanka' | c.name]"
qo = Head(Query(
metadata, symbols,
set,
@@ -234,7 +234,7 @@
#
# set [ c in IStudent; c.country >= "Sri Lanka" | c.name]
#
- query = "[c in IStudent; c.country >= 'Sri Lanka' | c.name]"
+ query = "set [c in IStudent; c.country >= 'Sri Lanka' | c.name]"
qo = Head(Query(
metadata, symbols,
set,
@@ -258,7 +258,7 @@
#
# set [ c in IStudent; c.country < "Sri Lanka" | c.name]
#
- query = "[c in IStudent; c.country < 'Sri Lanka' | c.name]"
+ query = "set [c in IStudent; c.country < 'Sri Lanka' | c.name]"
qo = Head(Query(
metadata, symbols,
set,
@@ -282,7 +282,7 @@
#
# set [ c in IStudent; c.country > "Sri Lanka" | c.name]
#
- query = "[c in IStudent; c.country > 'Sri Lanka' | c.name]"
+ query = "set [c in IStudent; c.country > 'Sri Lanka' | c.name]"
qo = Head(Query(
metadata, symbols,
set,
More information about the Checkins
mailing list