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

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset1a9f3c52176b
branchstable
phasepublic
hiddenno
parent revision#9d0f53bac016 new undo_modification context manager on select nodes
child revision#e1cc9656bb4c default is actually stable, #e154f58bb9d6 backport stable
files modified by this revision
ChangeLog
stcheck.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1309862978 -7200
# Tue Jul 05 12:49:38 2011 +0200
# Branch stable
# Node ID 1a9f3c52176b91f876db8a2a6b4833b6ed4ae496
# Parent 9d0f53bac0165ce21384aeed1b11e72f0dfee9c1
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

diff --git a/ChangeLog b/ChangeLog
@@ -1,11 +1,15 @@
1  ChangeLog for RQL
2  =================
3 
4  --
5 +    * remove_group_var renamed into remove_group_term and fixed implementation
6 
7 -	* fix remove_group_var renamed into remove_group_term and fixed implementation
8 +    * rql annotator add 'having' list into variable's stinfo, and
9 +      properly update variable graph
10 +
11 +    * new undo_modification context manager on select nodes
12 
13  2011-06-09  --  0.29.0
14      * support != operator for non equality
15      * support for CAST function
16      * support for regexp-based pattern matching using a REGEXP operator
diff --git a/stcheck.py b/stcheck.py
@@ -25,11 +25,11 @@
17  from logilab.database import UnknownFunction
18 
19  from rql._exceptions import BadRQLQuery
20  from rql.utils import function_description
21  from rql.nodes import (Relation, VariableRef, Constant, Not, Exists, Function,
22 -                       And, Variable, variable_refs, make_relation)
23 +                       And, Variable, Comparison, variable_refs, make_relation)
24  from rql.stmts import Union
25 
26 
27  def _var_graphid(subvarname, trmap, select):
28      try:
@@ -519,10 +519,27 @@
29          if node.having:
30              # if there is a having clause, bloc simplification of variables used in GROUPBY
31              for term in node.groupby:
32                  for vref in term.get_nodes(VariableRef):
33                      bloc_simplification(vref.variable, term)
34 +            try:
35 +                vargraph = node.vargraph
36 +            except AttributeError:
37 +                vargraph = None
38 +            # XXX node.having is a list of size 1
39 +            assert len(node.having) == 1
40 +            for term in node.having[0].get_nodes(Comparison):
41 +                for vref in term.iget_nodes(VariableRef):
42 +                    vref.variable.stinfo.setdefault('having', []).append(term)
43 +                if vargraph is not None:
44 +                    lhsvariables = set(vref.name for vref in term.children[0].get_nodes(VariableRef))
45 +                    rhsvariables = set(vref.name for vref in term.children[1].get_nodes(VariableRef))
46 +                    for v1 in lhsvariables:
47 +                        for v2 in rhsvariables:
48 +                            if v1 != v2:
49 +                                vargraph.setdefault(v1, []).append(v2)
50 +                                vargraph.setdefault(v2, []).append(v1)
51 
52      def rewrite_shared_optional(self, exists, var, identity_rel_scope=None):
53          """if variable is shared across multiple scopes, need some tree
54          rewriting
55          """