[Checkins]
SVN: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/
filter results retrieved by catalog.apply according to the operator
Charith Paranaliyanage
paranaliyanage at gmail.com
Thu Aug 7 22:13:58 EDT 2008
Log message for revision 89531:
filter results retrieved by catalog.apply according to the operator
Changed:
U Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.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/database/metadata.py
U Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py
U Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/interfaces.py
U Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/tests/test_zope.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-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/aoptimizer/aoptimizer.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -64,18 +64,10 @@
return tree.__parent__
#new algebra objects
- if operator == '==':
+ if operator:
makeFromIndex = MakeFromIndex(coll , coll, interface,
cond.split(".")[1],
- lowerbound=value, upperbound=value)
- elif operator == '>' or operator == '>=':
- makeFromIndex = MakeFromIndex(coll , coll, interface,
- cond.split(".")[1],
- lowerbound=value, upperbound=None)
- elif operator == '<' or operator == '<=':
- makeFromIndex = MakeFromIndex(coll , coll, interface,
- cond.split(".")[1],
- lowerbound=None, upperbound=value)
+ operator, value=value)
else:
return tree.__parent__
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-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/compiler.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -184,12 +184,12 @@
adapts(IMakeFromIndex)
def __call__(self):
- return '%s(metadata.getFromIndex("%s", "%s", %s, %s))' % (
+ return '%s(metadata.getFromIndex("%s", "%s", "%s", %s))' % (
self.context.coll1.__name__,
self.context.expr1,
self.context.expr2,
- self.context.lowerbound,
- self.context.upperbound)
+ self.context.operator,
+ self.context.value)
class IfCompiler(BaseCompiler):
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-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/compiler/optimize_index.txt 2008-08-08 02:13:57 UTC (rev 89531)
@@ -133,7 +133,7 @@
RunnableQuery:
reduce(set.union,
map(lambda i: set([i.name]),
- set(metadata.getFromIndex("IOptimizedClass", "value", 5, 5))), set())
+ set(metadata.getFromIndex("IOptimizedClass", "value", "==", 5))), set())
Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/database/metadata.py 2008-08-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/database/metadata.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -8,6 +8,7 @@
from zope.app.catalog.field import FieldIndex
from zope.app.intid import IIntIds
#import zc.relation.interfaces
+from BTrees.IFBTree import difference
from ocql.interfaces import IDB
from ocql.database.index import AllIndex
@@ -95,7 +96,7 @@
return None
- def getFromIndex(self, klass, property, lowerbound='A', upperbound='Z'):
+ def getFromIndex(self, klass, property, operator, value):
catalogs = getUtilitiesFor(ICatalog)
intids = getUtility(IIntIds)
for name, catalog in catalogs:
@@ -103,7 +104,25 @@
if isinstance(index, FieldIndex) and \
index.field_name == property and \
index.interface.__name__ == klass:
- results = catalog.apply({iname:(lowerbound, upperbound)})
+ if operator == '==':
+ results = catalog.apply({iname:(value, value)})
+ elif operator == '!=':
+ all = catalog.apply({iname:(None, None)})
+ temp = catalog.apply({iname:(value, value)})
+ results = difference(all, temp)
+ elif operator == '<=':
+ results = catalog.apply({iname:(value, None)})
+ elif operator == '<':
+ lt_eq = catalog.apply({iname:(value, None)})
+ temp = catalog.apply({iname:(value, value)})
+ results = difference(lt_eq, temp)
+ elif operator == '>=':
+ results = catalog.apply({iname:(None, value)})
+ elif operator == '>':
+ gt_eq = catalog.apply({iname:(None, value)})
+ temp = catalog.apply({iname:(value, value)})
+ results = difference(gt_eq, temp)
+
obj_list = [intids.getObject(result) for result in results]
return obj_list
#I could check whether property has an index by hasPropertyIndex.
Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py 2008-08-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/algebra.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -173,18 +173,18 @@
implements(IMakeFromIndex)
- def __init__(self, coll1, coll2, expr1, expr2, lowerbound='A', upperbound='Z'):
+ def __init__(self, coll1, coll2, expr1, expr2, operator, value):
BaseAlgebra.__init__(self)
self.setProp('expr1', expr1)
self.setProp('expr2', expr2)
self.setProp('coll1', coll1)
self.setProp('coll2', coll2)
- self.setProp('lowerbound', lowerbound)
- self.setProp('upperbound', upperbound)
+ self.setProp('operator', operator)
+ self.setProp('value', value)
def __repr__(self):
- return "MakeFromIndex(%s, %s, %s, %s, %s, %s)" % (
- self.coll1, self.coll2, self.expr1, self.expr2, self.lowerbound, self.upperbound)
+ return "MakeFromIndex(%s, %s, %s, %s, %s)" % (
+ self.coll1, self.coll2, self.expr1, self.expr2, self.value)
#class And:
Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/interfaces.py 2008-08-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/rewriter/interfaces.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -87,10 +87,9 @@
expr2 = Attribute('expression2')
coll1 = Attribute('first collection')
coll2 = Attribute('second collection')
- lowerbound = Attribute('lower bound of the query')
- upperbound = Attribute('upper bound of the query')
+ operator = Attribute('operator')
+ value = Attribute('boundary value of the query')
-
class IIf(IAlgebraObject):
"""Objects providing this interface represent the
If Algebra object
Modified: Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/tests/test_zope.py 2008-08-08 00:43:30 UTC (rev 89530)
+++ Sandbox/adamg/ocql/branches/optimize-with-index/src/ocql/tests/test_zope.py 2008-08-08 02:13:57 UTC (rev 89531)
@@ -168,7 +168,7 @@
Identifier(metadata, symbols, '"USA"'))
], Identifier(metadata, symbols, 'c.name')))
- self.doit(query, qo, set([metadata.getFromIndex('IStudent', 'country', 'USA', 'USA')[0].name]))
+ self.doit(query, qo, set([metadata.getFromIndex('IStudent', 'country','==', 'USA')[0].name]))
def test_suite():
More information about the Checkins
mailing list