[Checkins] SVN: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/
add interface declarations to query objects and implement
their location in the query object tree by parent-child relation
Charith Paranaliyanage
paranaliyanage at gmail.com
Tue Jul 8 22:13:52 EDT 2008
Log message for revision 88130:
add interface declarations to query objects and implement their location in the query object tree by parent-child relation
Changed:
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/interfaces.py
A Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/interfaces.py
U Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.py
-=-
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/interfaces.py 2008-07-09 00:19:51 UTC (rev 88129)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/interfaces.py 2008-07-09 02:13:51 UTC (rev 88130)
@@ -59,10 +59,25 @@
# Objects passed around
################
+class IObjectQueryHead(Interface):
+ """Represents head of the query object tree
+ """
+ tree = Attribute('Holds the root of the query object tree')
+
+# def rewrite(self):
+# """Rewrites query object in to algebra object"""
+
+class IObjectQueyChild(Interface):
+ """Objects providing this interface represents a child in the query object tree
+ """
+ children = Attribute('Children collection')
+
class IObjectQuery(Interface):
"""Objects providing this interface represent the OCQL query
as python objects
"""
+ metadata = Attribute('metadata')
+ symbols = Attribute('symbols')
class IOptimizedObjectQuery(Interface):
"""Objects providing this interface represent the OCQL query
Added: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/interfaces.py (rev 0)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/interfaces.py 2008-07-09 02:13:51 UTC (rev 88130)
@@ -0,0 +1,238 @@
+# -*- coding: UTF-8 -*-
+
+from zope.interface import Attribute, Interface
+from zope.schema import TextLine
+
+from ocql.interfaces import IObjectQuery, IObjectQueyChild
+
+class ITerm(IObjectQueyChild):
+ """Objects providing this interface represent the
+ Term Query object
+ """
+ identifier = Attribute('identifier')
+ expression = Attribute('attribute')
+
+class IExpression(ITerm, IObjectQuery):
+ """Objects providing this interface represent the
+ Expression Query object
+ """
+
+class IhasClassWith(IExpression):
+ """Objects providing this interface represent the
+ hasClassWith Query object
+ """
+ expression = Attribute('expression')
+ klass = Attribute('collection type')
+ conditional = Attribute('conditional')
+
+class IIdentifier(IExpression):
+ """Objects providing this interface represent the
+ Identifier Query object
+ """
+ name = TextLine()
+
+class IConstant(IExpression):
+ """Objects providing this interface represent the
+ Constant Query object
+ """
+ value = Attribute('constant value')
+
+class IStringConstant(IConstant):
+ """Objects providing this interface represent the
+ StringConstant Query object
+ """
+
+class INumericConstant(IConstant):
+ """Objects providing this interface represent the
+ NumericConstant Query object
+ """
+
+class IBooleanConstant(IConstant):
+ """Objects providing this interface represent the
+ BooleanConstant Query object
+ """
+
+class ICollectionConstant(IConstant):
+ """Objects providing this interface represent the
+ CollectionConstant Query object
+ """
+
+class IQuery(IExpression):
+ """Objects providing this interface represent the
+ Query object
+ """
+ collection_type = Attribute('collection type')
+ terms = Attribute('terms')
+ target = Attribute('target')
+
+class IIn(ITerm):
+ """Objects providing this interface represent the
+ In Query object
+ """
+
+class IAlias(ITerm):
+ """Objects providing this interface represent the
+ Alias Query object
+ """
+
+class IBinary(IExpression):
+ """Objects providing this interface represent the
+ Binary Query object
+ """
+ left = Attribute('left side of the binary expression')
+ right = Attribute('right side of the binary expression')
+
+class IUnion(IBinary):
+ """Objects providing this interface represent the
+ Union Query object
+ """
+
+class IDiffer(IBinary):
+ """Objects providing this interface represent the
+ Differ Query object
+ """
+
+class IAnd(IBinary):
+ """Objects providing this interface represent the
+ And Query object
+ """
+
+class IOr(IBinary):
+ """Objects providing this interface represent the
+ Or Query object
+ """
+
+class IProperty(IBinary):
+ """Objects providing this interface represent the
+ Property Query object
+ """
+
+class IIndex(IBinary):
+ """Objects providing this interface represent the
+ Index Query object
+ """
+
+class IArithmetic(IBinary):
+ """Objects providing this interface represent the
+ Arithmetic Query object
+ """
+
+class IAdd(IArithmetic):
+ """Objects providing this interface represent the
+ Add Query object
+ """
+class IMul(IArithmetic):
+ """Objects providing this interface represent the
+ Multiplication Query object
+ """
+
+class ISub(IArithmetic):
+ """Objects providing this interface represent the
+ Subtract Query object
+ """
+
+class IDiv(IArithmetic):
+ """Objects providing this interface represent the
+ Division Query object
+ """
+
+class IUnary(IExpression):
+ """Objects providing this interface represent the
+ Unary Query object
+ """
+ expression = Attribute('expression')
+
+class INot(IUnary):
+ """Objects providing this interface represent the
+ Not Query object
+ """
+
+class IAggregate(IUnary):
+ """Objects providing this interface represent the
+ Aggregate Query object
+ """
+
+class ICount(IAggregate):
+ """Objects providing this interface represent the
+ Count Query object
+ """
+
+class ISum(IAggregate):
+ """Objects providing this interface represent the
+ Sum Query object
+ """
+
+class IQuantor(IObjectQuery):
+ """Objects providing this interface represent the
+ Quantor Query object
+ """
+ expr = Attribute('expression')
+
+class IQuanted(IObjectQueyChild):
+ """Objects providing this interface represent the
+ Quanted Query object
+ """
+ quantor = Attribute('quantor')
+ expression = Attribute('expression')
+
+class IEvery(IQuantor):
+ """Objects providing this interface represent the
+ Every Query object
+ """
+
+class ISome(IQuantor):
+ """Objects providing this interface represent the
+ Some Query object
+ """
+
+class IAtmost(IQuantor):
+ """Objects providing this interface represent the
+ Atmost Query object
+ """
+
+class IAtleast(IQuantor):
+ """Objects providing this interface represent the
+ Atleast Query object
+ """
+
+class IJust(IQuantor):
+ """Objects providing this interface represent the
+ Just Query object
+ """
+
+class ICondition(IExpression):
+ """Objects providing this interface represent the
+ Condition Query object
+ """
+ left = Attribute('left side of the condition')
+ right = Attribute('right side of the condition')
+
+class IEq(ICondition):
+ """Objects providing this interface represent the
+ Equal Query object
+ """
+
+class INe(ICondition):
+ """Objects providing this interface represent the
+ Negation Query object
+ """
+
+class ILt(ICondition):
+ """Objects providing this interface represent the
+ Less than Query object
+ """
+
+class IGt(ICondition):
+ """Objects providing this interface represent the
+ Greater than Query object
+ """
+
+class ILe(ICondition):
+ """Objects providing this interface represent the
+ Less than or Equal Query object
+ """
+
+class IGe(ICondition):
+ """Objects providing this interface represent the
+ Greater than or Equal Query object
+ """
Property changes on: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/interfaces.py
___________________________________________________________________
Name: svn:executable
+ *
Modified: Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.py
===================================================================
--- Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.py 2008-07-09 00:19:51 UTC (rev 88129)
+++ Sandbox/adamg/ocql/branches/qo-compiler/src/ocql/queryobject/queryobject.py 2008-07-09 02:13:51 UTC (rev 88130)
@@ -15,10 +15,25 @@
#implement a traversable tree of queryobjects (parent, child, sibling, ....)
from zope.interface import implements
+from zope.location import locate, Location
-from ocql.interfaces import IObjectQuery
+from ocql.interfaces import IObjectQuery, IObjectQueryHead, IObjectQueyChild
+from ocql.queryobject.interfaces import *
-class QueryObject:
+class Head:
+ implements(IObjectQueryHead)
+ def __init__(self, tree):
+ self.name = 'head'
+ self.tree = tree
+
+ def rewrite(self):
+ return self.tree
+
+class Child:
+ implements(IObjectQueyChild)
+ children = []
+
+class QueryObject(Child, Location):
#TODO: this is dirty here, at the end we'll need to have a tree of
#QueryObject's whose topmost element will only get this IF
implements(IObjectQuery)
@@ -57,17 +72,31 @@
def rewrite(self, algebra):
raise NotImplementedError(self)
-class Term:
- pass
+class Term(Child):
+ implements(ITerm)
+ identifier = None
+ expression = None
+ def __init__(self, metadata, symbols, identifier, expression):
+ self.metadata = metadata
+ self.symbols = symbols
+ self.identifier = identifier
+ self.expression = expression
+ locate(identifier, self, 'identifier')
+ locate(expression, self, 'expression')
+ self.children.extend([identifier, expression])
+
+
class Expression(Term, QueryObject):
- pass
+ implements(IExpression)
#
# General
#
class hasClassWith(Expression):
#NotImplementedError
+ implements(IhasClassWith)
+
expression = None
klass = None
conditional = None
@@ -78,14 +107,19 @@
self.expression = expr
self.klass = klass
self.conditional = conditional
+ locate(expr, self, 'expr')
+ locate(conditional, self, 'conditional')
+ self.children.extend([expr, klass, conditional])
class Identifier(Expression):
+ implements(IIdentifier)
name = None
def __init__(self, metadata, symbols, name):
self.metadata = metadata
self.symbols = symbols
self.name = name
+ self.children.append(name)
def __repr__(self):
return "%s(%s)" % (
@@ -97,6 +131,7 @@
return algebra.Identifier(self.name)
class Constant(Expression):
+ implements(IConstant)
#this shall be abstract?
value = None
@@ -104,6 +139,7 @@
self.metadata = metadata
self.symbols = symbols
self.value=value
+ self.children.append(value)
def __repr__(self):
return "%s(%s)" % (
@@ -127,6 +163,7 @@
pass
class Query(Expression):
+ implements(IQuery)
collection_type = None
terms = None
target = None
@@ -137,6 +174,11 @@
self.collection_type = collection_type
self.terms = terms
self.target = target
+ for term in terms:
+ locate(term, self, 'term')
+ if target is not None: locate(target, self, 'target')
+ self.children.extend(terms)
+ self.children.extend([collection_type,target])
def __repr__(self):
return "%s(%s, %s, %s)" % (
@@ -210,16 +252,8 @@
self.symbols.dellevel()
return rv
-class In(Term):
- identifier = None
- expression = None
-
- def __init__(self, metadata, symbols, identifier, expression):
- self.metadata = metadata
- self.symbols = symbols
- self.identifier = identifier
- self.expression = expression
-
+class In(Term):
+ implements(IIn)
def __repr__(self):
return "%s(%s, %s)" % (
self.__class__.__name__,
@@ -238,15 +272,7 @@
return rv
class Alias(Term):
- identifier = None
- expression = None
-
- def __init__(self, metadata, symbols, identifier, expression):
- self.metadata = metadata
- self.symbols = symbols
- self.identifier = identifier
- self.expression = expression
-
+ implements(IAlias)
def __repr__(self):
return "%s(%s, %s)" % (
self.__class__.__name__,
@@ -270,6 +296,7 @@
# Binary operators
#
class Binary(Expression):
+ implements(IBinary)
left = None
right = None
@@ -278,6 +305,9 @@
self.symbols = symbols
self.left = left
self.right = right
+ locate(left, self, 'left')
+ locate(right, self, 'right')
+ self.children.extend([left, right])
def __repr__(self):
return "%s(%s, %s)" % (
@@ -293,6 +323,7 @@
# Sets and properties
class Union(Binary):
+ implements(IUnion)
def rewrite(self, algebra):
return algebra.Union(
self.left.get_collection_type(),
@@ -300,6 +331,7 @@
self.right.rewrite(algebra))
class Differ(Binary):
+ implements(IDiffer)
def rewrite(self, algebra):
return algebra.Differ(
self.left.get_collection_type(),
@@ -307,14 +339,17 @@
self.right.rewrite(algebra))
class And(Binary):
+ implements(IAnd)
def get_operator(self, algebra):
return algebra.Operator('and')
class Or(Binary):
+ implements(IOr)
def get_operator(self, algebra):
return algebra.Operator('or')
class Property(Binary):
+ implements(IProperty)
def rewrite(self, algebra): # FIXME: Ezt gondold at...
return algebra.Identifier(
'.'.join([self.left.name, self.right.name]))
@@ -337,26 +372,30 @@
class Index(Binary):
#NotImplementedError
- pass
+ implements(IIndex)
# Arithmetic operators
class Arithmetic(Binary):
- pass
+ implements(IArithmetic)
class Add(Arithmetic):
+ implements(IAdd)
def get_operator(self, algebra):
return algebra.Operator('+')
class Mul(Arithmetic):
+ implements(IMul)
def get_operator(self, algebra):
return algebra.Operator('*')
class Sub(Arithmetic):
+ implements(ISub)
def get_operator(self, algebra):
return algebra.Operator('-')
class Div(Arithmetic):
+ implements(IDiv)
def get_operator(self, algebra):
return algebra.Operator('/')
@@ -364,12 +403,15 @@
# Unary operators
#
class Unary(Expression):
+ implements(IUnary)
expression = None
def __init__(self, metadata, symbols, expression):
self.metadata = metadata
self.symbols = symbols
self.expression = expression
+ locate(expression, self, 'expression')
+ self.children.append(expression)
def __repr__(self):
return "%s(%s)" % (
@@ -378,13 +420,16 @@
)
class Not(Unary):
+ implements(INot)
def rewrite(self, algebra):
return algebra.Not(self.expression.rewrite(algebra))
class Aggregate(Unary):
- pass
+ implements(IAggregate)
+
class Count(Aggregate):
+ implements(ICount)
def rewrite(self, algebra):
return algebra.Reduce(
bag, # FIXME milyen bag
@@ -397,16 +442,18 @@
class Sum(Aggregate):
#NotImplementedError
- pass
+ implements(ISum)
#
# Conditional
#
class Quantor(QueryObject):
+ implements(IQuantor)
def __init__(self, metadata, symbols, expr):
self.metadata = metadata
self.symbols = symbols
self.expr = expr
+ self.children.append(expr)
def __repr__(self):
return "(%s)" % (
@@ -416,7 +463,8 @@
def rewrite(self, algebra, expression, quanter, operator):
raise NotImplementedError()
-class Quanted:
+class Quanted(Child):
+ implements(IQuanted)
quantor = None
expression = None
@@ -425,12 +473,16 @@
self.symbols = symbols
self.quantor = quantor
self.expression = expression
+ locate(quantor, self, 'quantor')
+ locate(expression, self, 'expression')
+ self.children.extend([quantor, expression])
def rewrite(self, algebra, expression, operator):
return self.quantor.rewrite(algebra, expression, self.expression, operator)
# Quantors
class Every(Quantor):
+ implements(IEvery)
def rewrite(self, algebra, expression, quanted, operator):
ctype = quanted.get_collection_type()
@@ -453,6 +505,7 @@
)
class Some(Quantor):
+ implements(ISome)
def rewrite(self, algebra, expression, quanted, operator):
ctype = quanted.get_collection_type()
return algebra.Reduce(
@@ -471,7 +524,7 @@
)
class Atmost(Quantor):
- pass
+ implements(IAtmost)
#expr = None
#def __init__(self, metadata, symbols, expr):
@@ -481,7 +534,7 @@
# self.expr = expr
class Atleast(Quantor):
- pass
+ implements(IAtleast)
#expr = None
#def __init__(self, metadata, symbols, expr):
@@ -491,7 +544,7 @@
# self.expr = expr
class Just(Quantor):
- pass
+ implements(IJust)
#expr = None
#def __init__(self, metadata, symbols, expr):
@@ -502,6 +555,7 @@
# Logical operators
class Condition(Expression):
+ implements(ICondition)
left = None
right = None
@@ -510,6 +564,9 @@
self.symbols = symbols
self.left = left
self.right = right
+ locate(left, self, 'left')
+ locate(right, self, 'right')
+ self.children.extend([left, right])
def rewrite(self, algebra):
if isinstance(self.left, Quanted):
@@ -526,26 +583,32 @@
return algebra.Binary(self.left.rewrite(algebra), self.get_operator(algebra), self.right.rewrite(algebra))
class Eq(Condition):
+ implements(IEq)
def get_operator(self, algebra):
return algebra.Operator('==')
class Ne(Condition):
+ implements(INe)
def get_operator(self, algebra):
return algebra.Operator('!=')
class Lt(Condition):
+ implements(ILt)
def get_operator(self, algebra):
return algebra.Operator('<')
class Gt(Condition):
+ implements(IGt)
def get_operator(self, algebra):
return algebra.Operator('>')
class Le(Condition):
+ implements(ILe)
def get_operator(self, algebra):
return algebra.Operator('<=')
class Ge(Condition):
+ implements(IGe)
def get_operator(self, algebra):
return algebra.Operator('>=')
More information about the Checkins
mailing list