closes #70416: add 'having' list into variable's stinfo and properly update variable graph stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 05 Jul 2011 12:49:38 +0200
branchstable
changeset 639 1a9f3c52176b
parent 638 9d0f53bac016
child 640 e154f58bb9d6
child 646 e1cc9656bb4c
closes #70416: add 'having' list into variable's stinfo and properly update variable graph # variable stinfo should hold term (Comparison node) where it's referenced in having clause (var.stinfo.get('having') # should properly update statement's vargraph
ChangeLog
stcheck.py
--- a/ChangeLog	Fri Jul 01 15:30:06 2011 +0200
+++ b/ChangeLog	Tue Jul 05 12:49:38 2011 +0200
@@ -2,8 +2,12 @@
 =================
 
 --
+    * remove_group_var renamed into remove_group_term and fixed implementation
 
-	* fix remove_group_var renamed into remove_group_term and fixed implementation
+    * rql annotator add 'having' list into variable's stinfo, and
+      properly update variable graph
+
+    * new undo_modification context manager on select nodes
 
 2011-06-09  --  0.29.0
     * support != operator for non equality
--- a/stcheck.py	Fri Jul 01 15:30:06 2011 +0200
+++ b/stcheck.py	Tue Jul 05 12:49:38 2011 +0200
@@ -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,
-                       And, Variable, variable_refs, make_relation)
+                       And, Variable, Comparison, variable_refs, make_relation)
 from rql.stmts import Union
 
 
@@ -521,6 +521,23 @@
             for term in node.groupby:
                 for vref in term.get_nodes(VariableRef):
                     bloc_simplification(vref.variable, term)
+            try:
+                vargraph = node.vargraph
+            except AttributeError:
+                vargraph = None
+            # XXX node.having is a list of size 1
+            assert len(node.having) == 1
+            for term in node.having[0].get_nodes(Comparison):
+                for vref in term.iget_nodes(VariableRef):
+                    vref.variable.stinfo.setdefault('having', []).append(term)
+                if vargraph is not None:
+                    lhsvariables = set(vref.name for vref in term.children[0].get_nodes(VariableRef))
+                    rhsvariables = set(vref.name for vref in term.children[1].get_nodes(VariableRef))
+                    for v1 in lhsvariables:
+                        for v2 in rhsvariables:
+                            if v1 != v2:
+                                vargraph.setdefault(v1, []).append(v2)
+                                vargraph.setdefault(v2, []).append(v1)
 
     def rewrite_shared_optional(self, exists, var, identity_rel_scope=None):
         """if variable is shared across multiple scopes, need some tree