closes #72052: new optional 'optcomparisons' key in variable stinfo

containing HAVING comparison nodes where it's used and optional (eg outer join)

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset7decc7f6c23f
branchstable
phasepublic
hiddenno
parent revision#4990981c1826 closes #72295: add some missing operators
child revision#4f1ca9594a30 closes #69185: syntax error with unary operators
files modified by this revision
ChangeLog
stcheck.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1312297540 -7200
# Tue Aug 02 17:05:40 2011 +0200
# Branch stable
# Node ID 7decc7f6c23f740e0a82a6d68b69dbd31bb9db58
# Parent 4990981c18262742f4df575ec51421d2afdcbd85
closes #72052: new optional 'optcomparisons' key in variable stinfo

containing HAVING comparison nodes where it's used and optional (eg outer join)

diff --git a/ChangeLog b/ChangeLog
@@ -1,20 +1,26 @@
1  ChangeLog for RQL
2  =================
3 
4  	--
5 -    * fix Comparison.as_string to considerer its optional attribute
6 +
7      * add some missing operators (#72295):
8 
9        * % (modulo),
10        * ^ (power),
11        * & (bitwise AND),
12        * | (bitwise OR),
13        * # (bitwise XOR),
14        * << (bitwise left shift),
15        * >> (bitwise right shift)
16 
17 +    * new #72052: optional 'optcomparisons' key in variable stinfo, containing
18 +      HAVING comparison nodes where it's used and optional (eg outer
19 +      join)
20 +
21 +    * fix Comparison.as_string to considerer its optional attribute
22 +
23  2011-07-27  --  0.29.1
24      * #70264: remove_group_var renamed into remove_group_term and fixed
25        implementation
26 
27      * #70416: rql annotator add 'having' list into variable's stinfo, and
diff --git a/stcheck.py b/stcheck.py
@@ -526,20 +526,30 @@
28              except AttributeError:
29                  vargraph = None
30              # XXX node.having is a list of size 1
31              assert len(node.having) == 1
32              for term in node.having[0].get_nodes(Comparison):
33 -                for vref in term.iget_nodes(VariableRef):
34 -                    vref.variable.stinfo.setdefault('having', []).append(term)
35 +                lhsvariables = set(vref.variable for vref in term.children[0].get_nodes(VariableRef))
36 +                rhsvariables = set(vref.variable for vref in term.children[1].get_nodes(VariableRef))
37 +                for var in lhsvariables | rhsvariables:
38 +                    var.stinfo.setdefault('having', []).append(term)
39                  if vargraph is not None:
40 -                    lhsvariables = set(vref.name for vref in term.children[0].get_nodes(VariableRef))
41 -                    rhsvariables = set(vref.name for vref in term.children[1].get_nodes(VariableRef))
42                      for v1 in lhsvariables:
43 +                        v1 = v1.name
44                          for v2 in rhsvariables:
45 +                            v2 = v2.name
46                              if v1 != v2:
47                                  vargraph.setdefault(v1, []).append(v2)
48                                  vargraph.setdefault(v2, []).append(v1)
49 +                if term.optional in ('left', 'both'):
50 +                    for var in lhsvariables:
51 +                        optcomps = var.stinfo['attrvar'].stinfo.setdefault('optcomparisons', set())
52 +                        optcomps.add(term)
53 +                if term.optional in ('right', 'both'):
54 +                    for var in rhsvariables:
55 +                        optcomps = var.stinfo['attrvar'].stinfo.setdefault('optcomparisons', set())
56 +                        optcomps.add(term)
57 
58      def rewrite_shared_optional(self, exists, var, identity_rel_scope=None):
59          """if variable is shared across multiple scopes, need some tree
60          rewriting
61          """