Commit 6e672270 authored by François Ferry's avatar François Ferry
Browse files

fix(annotation): check Function children to detect potential aggragation.

Without this, we have an error if we have aggregate functions indise other
function.

related: cubicweb#242
parent e3d13fc1721c
Pipeline #99897 passed with stages
in 3 minutes and 53 seconds
......@@ -21,6 +21,7 @@ from logilab.common.graph import has_path
from logilab.database import UnknownFunction
from rql._exceptions import BadRQLQuery
from rql.rqltypes import BaseNode
from rql.utils import function_description
from rql.nodes import (
Relation,
......@@ -610,6 +611,17 @@ class RQLSTChecker:
pass
def _check_aggregat_rec(node: BaseNode) -> bool:
for func in node.iget_nodes(Function):
if func.descr().aggregat:
return True
for child in node.children:
has_aggregat = _check_aggregat_rec(child)
if has_aggregat:
return True
return False
class RQLSTAnnotator:
"""Annotate RQL syntax tree to ease further code generation from it.
......@@ -630,10 +642,8 @@ class RQLSTAnnotator:
for var in node.defined_vars.values():
var.prepare_annotation()
for i, term in enumerate(node.selection):
for func in term.iget_nodes(Function):
if func.descr().aggregat:
node.has_aggregat = True
break
if _check_aggregat_rec(term):
node.has_aggregat = True
# register the selection column index
for vref in term.get_nodes(VariableRef):
vref.variable.stinfo["selected"].add(i)
......
......@@ -349,6 +349,14 @@ class AnnotateTest(unittest.TestCase):
rqlst = self.parse("Any X WHERE X eid IN (1,2,3)").children[0]
self.assertTrue(rqlst.defined_vars["X"].stinfo["uidrel"])
def test_has_aggregat_no_aggregat(self):
rqlst = self.parse("Any ABS(X) WHERE X is Person").children[0]
self.assertFalse(rqlst.has_aggregat)
def test_nested_aggregat_detected(self):
rqlst = self.parse("Any ABS(COUNT(X)) WHERE X is Person").children[0]
self.assertTrue(rqlst.has_aggregat)
if __name__ == "__main__":
unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment