[ https://issues.apache.org/jira/browse/JENA-1010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14702754#comment-14702754 ]
Andy Seaborne commented on JENA-1010: ------------------------------------- {{?.0}} is an internally generated variable used to assign the value of {{(count ?o)}} -- this is than assigned to {{?c}} and {{?.0}} is invisible. {{(group (?prop) ((?.0 (count ?o)))}} is calculate the group and aggregate count into ?.0. There are various times internal variables are generated - they are always synactically illegal names to avoid clashes with any used in the query. You can see {{?/x}} sometimes, even {{?//x}}. {{(extend)}} is the algebra operator for {{BIND}}. It is done via a temporary because {noformat} SELECT (count(*) AS ?c1) (count(*) AS ?c2) { .... } {noformat} or {noformat} SELECT (count(*) AS ?c1) { ... } HAVING (count(*) > 2) {noformat} still only calculates {{count(*)}} once. You see {{(filter (> ?.0 1)}} because the {{HAVING}} has no {{AS}}. > Wrong parsing of aggregate functions in HAVING clause > ----------------------------------------------------- > > Key: JENA-1010 > URL: https://issues.apache.org/jira/browse/JENA-1010 > Project: Apache Jena > Issue Type: Bug > Components: Jena > Affects Versions: Jena 2.13.0 > Reporter: Ruben Navarro Piris > Assignee: Andy Seaborne > Fix For: Jena 3.0.0 > > > Using an aggregate funtion (count) in the HAVING clause leads to some weird > parsing. The following code reproduces the problem (output also provided) > {code:java} > public class Test { > public static void main(String[] args) { > AlgebraGenerator ag = new AlgebraGenerator(); > // this query counts the number of occurrences of a property > // showing only properties with more than one occurrence > String q = > "SELECT (count(?o) AS ?c) ?prop " > + "WHERE { GRAPH ?g { ?s ?prop ?o } } " > + "GROUP BY ?prop HAVING ( count(?o) > 1 ) " > + "ORDER BY DESC(?c) ?prop"; > Query query = QueryFactory.create(q); > System.out.println(query); > Op queryOp = ag.compile(query); > System.out.println(queryOp); > > Query rewritten = OpAsQuery.asQuery(queryOp); > System.out.println(rewritten); > } > } > {code} > {code} > SELECT (COUNT(?o) AS ?c) ?prop > WHERE > { GRAPH ?g > { ?s ?prop ?o} > } > GROUP BY ?prop > HAVING ( COUNT(?o) > 1 ) > ORDER BY DESC(?c) ?prop > (project (?c ?prop) > (order ((desc ?c) ?prop) > (filter (> ?.0 1) > (extend ((?c ?.0)) > (group (?prop) ((?.0 (count ?o))) > (graph ?g > (bgp (triple ?s ?prop ?o)))))))) > SELECT ?c ?prop > WHERE > { { GRAPH ?g > { ?s ?prop ?o} > BIND(COUNT(?o) AS ?c) > } > FILTER ( ?.0 > 1 ) > } > GROUP BY ?prop > ORDER BY DESC(?c) ?prop > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)