Dimitris Kontokostas created JENA-766: -----------------------------------------
Summary: Aggregate reports possible wrong results Key: JENA-766 URL: https://issues.apache.org/jira/browse/JENA-766 Project: Apache Jena Issue Type: Bug Components: Jena Affects Versions: Jena 2.11.2 Environment: Ubuntu 14.04 Reporter: Dimitris Kontokostas Priority: Minor I have the following query {code:title=SPARQL-Query} PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT (COUNT (DISTINCT ?resource) as ?total) WHERE { ?resource rdf:type/rdfs:subClassOf* <http://example.com/ns#CardExact3Class>. ?resource <http://example.com/ns#cardExact3> ?c. } GROUP BY ?resource HAVING ( ( count(?c) != 3 ) && ( count(?c) != 0 ) ) {code} run against the following data {code:title=TTL-Data} @prefix ex: <http://example.com/ns#> . ex:error3a a ex:CardExact3Class ; # 1 error ex:cardExact3 ex:abc1 ; ex:cardExact3 ex:abc2 . ex:error3b a ex:CardExact3Class ; # 1 error ex:cardExact3 ex:abc1 ; ex:cardExact3 ex:abc2 ; ex:cardExact3 ex:abc3 ; ex:cardExact3 ex:abc4 . {code} The query should return 2 as result but instead returns 1. If I change the query type to SELECT DISTINCT ?resource I get 2 results so I think this should be a Jena issue (but maybe I miss something again) Here's some sample Java code to reproduce {code:title=Java code to reproduce} Model model = ModelFactory.createDefaultModel(); String Query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "SELECT (COUNT (DISTINCT ?resource) as ?total) WHERE {\n" + "\t?resource rdf:type/rdfs:subClassOf* <http://example.com/ns#CardExact3Class>.\n" + "\t?resource <http://example.com/ns#cardExact3> ?c.\n" + "} GROUP BY ?resource\n" + "HAVING ( ( count(?c) != 3 ) && ( count(?c) != 0 ) )\n" + "\n" + " "; String data = "@prefix ex: <http://example.com/ns#> .\n\n" + "ex:error3a a ex:CardExact3Class ; # 1 error\n" + "\tex:cardExact3 ex:abc1 ;\n" + "\tex:cardExact3 ex:abc2 ;\n" + "\t.\n" + "ex:error3b a ex:CardExact3Class ; # 1 error\n" + " \tex:cardExact3 ex:abc1 ;\n" + " \tex:cardExact3 ex:abc2 ;\n" + " \tex:cardExact3 ex:abc3 ;\n" + " \tex:cardExact3 ex:abc4 ;\n" + " \t.\n"; model.read(new ByteArrayInputStream( data.getBytes() ), null, "TTL"); QueryExecution qe = com.hp.hpl.jena.query.QueryExecutionFactory.create(Query, model); ResultSet results = qe.execSelect(); if (results.hasNext()) { QuerySolution qs = results.next(); int total = qs.get("total").asLiteral().getInt(); // Total should be 2 while it is 1 } {code} -- This message was sent by Atlassian JIRA (v6.2#6252)