[rql2sql] support for outer join on column alias (closes #1979645) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 04 Oct 2011 10:15:45 +0200
branchstable
changeset 7902 2ada3052e626
parent 7900 e9b79f5c3571
child 7903 ac658ab4c7b7
[rql2sql] support for outer join on column alias (closes #1979645)
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/sources/rql2sql.py	Fri Sep 30 18:08:00 2011 +0200
+++ b/server/sources/rql2sql.py	Tue Oct 04 10:15:45 2011 +0200
@@ -1426,10 +1426,18 @@
             return sql
         leftvars = cmp.children[0].get_nodes(VariableRef)
         assert len(leftvars) == 1
-        leftalias = self._var_table(leftvars[0].variable.stinfo['attrvar'])
+        if leftvars[0].variable.stinfo['attrvar'] is None:
+            assert isinstance(leftvars[0].variable, ColumnAlias)
+            leftalias = leftvars[0].variable._q_sqltable
+        else:
+            leftalias = self._var_table(leftvars[0].variable.stinfo['attrvar'])
         rightvars = cmp.children[1].get_nodes(VariableRef)
         assert len(rightvars) == 1
-        rightalias = self._var_table(rightvars[0].variable.stinfo['attrvar'])
+        if rightvars[0].variable.stinfo['attrvar'] is None:
+            assert isinstance(rightvars[0].variable, ColumnAlias)
+            rightalias = rightvars[0].variable._q_sqltable
+        else:
+            rightalias = self._var_table(rightvars[0].variable.stinfo['attrvar'])
         if optional == 'right':
             self._state.replace_tables_by_outer_join(
                 leftalias, rightalias, 'LEFT', sql)
--- a/server/test/unittest_rql2sql.py	Fri Sep 30 18:08:00 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Tue Oct 04 10:15:45 2011 +0200
@@ -1524,6 +1524,12 @@
 FROM (SELECT MAX(_A.cw_ordernum) AS C0
 FROM cw_CWAttribute AS _A) AS _T0, cw_CWAttribute AS _A
 WHERE _A.cw_ordernum=_T0.C0'''),
+
+            ('Any O1 HAVING O1=O2? WITH O1 BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute), O2 BEING (Any MAX(O) WHERE A ordernum O, A is CWRelation)',
+             '''SELECT _T0.C0
+FROM (SELECT MAX(_A.cw_ordernum) AS C0
+FROM cw_CWAttribute AS _A) AS _T0 LEFT OUTER JOIN (SELECT MAX(_A.cw_ordernum) AS C0
+FROM cw_CWRelation AS _A) AS _T1 ON (_T0.C0=_T1.C0)'''),
             )):
             yield t