enhance rewrite_shared_optional so one can specify where the new identity relation should be added (used by cw multi-sources planner)
--- a/nodes.py Wed Nov 03 16:43:34 2010 +0100
+++ b/nodes.py Fri Jan 07 14:54:19 2011 +0100
@@ -440,7 +440,12 @@
return False
rhs = self.children[1]
if isinstance(rhs, Comparison):
- rhs = rhs.children[0]
+ try:
+ rhs = rhs.children[0]
+ except:
+ print 'opppp', rhs
+ print rhs.root
+ raise
# else: relation used in SET OR DELETE selection
return ((isinstance(rhs, Constant) and rhs.type == 'etype')
or (isinstance(rhs, Function) and rhs.name == 'IN'))
--- a/stcheck.py Wed Nov 03 16:43:34 2010 +0100
+++ b/stcheck.py Fri Jan 07 14:54:19 2011 +0100
@@ -27,7 +27,7 @@
from rql._exceptions import BadRQLQuery
from rql.utils import function_description
from rql.nodes import (Relation, VariableRef, Constant, Not, Exists, Function,
- Variable, variable_refs)
+ And, Variable, variable_refs, make_relation)
from rql.stmts import Union
@@ -517,7 +517,7 @@
for vref in term.get_nodes(VariableRef):
bloc_simplification(vref.variable, term)
- def rewrite_shared_optional(self, exists, var):
+ def rewrite_shared_optional(self, exists, var, identity_rel_scope=None):
"""if variable is shared across multiple scopes, need some tree
rewriting
"""
@@ -574,9 +574,14 @@
newvar.stinfo['possibletypes'] = var.stinfo['possibletypes']
for sol in newvar.stmt.solutions:
sol[newvar.name] = sol[var.name]
- rel = exists.add_relation(var, 'identity', newvar)
+ if identity_rel_scope is None:
+ rel = exists.add_relation(var, 'identity', newvar)
+ identity_rel_scope = exists
+ else:
+ rel = make_relation(var, 'identity', (newvar,), VariableRef)
+ exists.parent.replace(exists, And(exists, Exists(rel)))
# we have to force visit of the introduced relation
- self.visit_relation(rel, exists)
+ self.visit_relation(rel, identity_rel_scope)
return newvar
# tree nodes ##############################################################