SmartDataAnalytics / jena-sparql-api

A collection of Jena-extensions for hiding SPARQL-complexity from the application layer
Other
57 stars 14 forks source link

COUNT(*) is not working with pagination #5

Closed MichaelRoeder closed 10 years ago

MichaelRoeder commented 10 years ago

I used a QueryExecutionFactory created as described in the tutorial: QueryExecutionFactoryHttp(endpoint) QueryExecutionFactoryDelay(qef, DELAY) QueryExecutionFactoryCacheEx(qef, cacheFrontend) QueryExecutionFactoryPaginated(qef, 100)

Using http://cr.eionet.europa.eu/sparql as endpoint the SPARQL query

SELECT COUNT(*) AS ?COUNT WHERE { ?a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat> }

fails with the following Exception: com.hp.hpl.jena.query.QueryParseException: Encountered " "count" "COUNT "" at line 1, column 8. Was expecting one of:

... ... "distinct" ... "reduced" ... "(" ... "*" ... ``` at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102) at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53) at com.hp.hpl.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:37) at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:156) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:79) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:52) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40) at org.aksw.jena_sparql_api.core.QueryExecutionFactoryBackQuery.createQueryExecution(QueryExecutionFactoryBackQuery.java:19) at org.aksw.topics4lod.sparql.VoidExtractor.queryCounts(VoidExtractor.java:105) at org.aksw.topics4lod.sparql.VoidExtractor.extractVoidInfo(VoidExtractor.java:68) at org.aksw.topics4lod.sparql.VoidExtractor.main(VoidExtractor.java:52) ``` The same code works with the same query without any problems, if the pagination (QueryExecutionFactoryPaginated) is not used. So it seems that the pagination has a problem with count queries.
jimkont commented 10 years ago

Can you try your query in http://www.sparql.org/query-validator.html and check if it is valid?

MichaelRoeder commented 10 years ago

Hi, thanks for this hint. The validator gave the same error. It turns out that the endpoint itself accepts the SPARQL query as I posted it in the first comment. However, the pagination class as well as the query validator only accepts the "count" in brackets as it is described in the SPARQL standard (there is an example in section 18.2.4.1 on http://www.w3.org/TR/sparql11-query ).

So, my query should look like:

SELECT (COUNT(*) AS ?COUNT) WHERE { ?a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat> }

Thanks again and sorry for opening this issue.