1
votes

I want to get total count of sparql query results. I am using jena API for this in java. count query is working in virtuoso but its not working in java using jena api.

Sparql Query:

select ( count ( ?name ) AS ?total ) from < mygraph > 
where { ?name rdf:type foaf:Name}

Its not working in jena API. I have read http://www.w3.org/2001/sw/DataAccess/issues#countAggregate So I think its not working in rdf but its working in Virtuoso sparql editor. So if u have a solution then plz let me know.And also tell me if there is alternative solution.

Thank you

Here is my java code,

String countQueryString="select ( count ( ?name ) AS ?total ) from < mygraph > 
where { ?name rdf:type foaf:Name}";
Query selectQuery = QueryFactory.create(countQueryString);
        QueryExecution qe = QueryExecutionFactory.sparqlService(Constant.SPARQL_ENDPOINT, selectQuery);
Resultset results=qe.execSelect();
if(results.hasNext())
{
    totalCount=countResult.next().get("total").toString();
}

Below is the exception: HttpException: HttpException: 400 Bad Request: HttpException: 400 Bad Request.....

1
What do you mean “it's not working”? What's happening? Any error messages etc? How are you trying to run the query in the Jena API? - cygri
Showing some code that uses the Jena API would be useful. - MikeJ
Here is the java code that i am using for this query. - Raxit

1 Answers

2
votes

Take a look at the ARQ documentation for aggregate support (I encountered similar issues)

http://jena.apache.org/documentation/query/group-by.html

It seems that it doesn't support

(count(?variable) as ?binding)

In the past I have also tried removing the parenthesis around the aggregate projection i.e:

select count ( ?name ) AS ?total from < mygraph > where { ?name rdf:type foaf:Name}

But this was because Virtuoso actually had an issue with them.