Ruben Navarro Piris created JENA-1010:
-----------------------------------------

             Summary: 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


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)

Reply via email to