Use one of the .addOrderBy() methods on the Query object - 
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Query.html#addOrderBy-org.apache.jena.sparql.expr.Expr-int-

 

If you are building lots of queries programmatically the higher level Query 
Builder API may be more user friendly - 
https://jena.apache.org/documentation/extras/querybuilder/index.html

 

Rob

 

From: Andreas Kahl <[email protected]>
Reply-To: <[email protected]>
Date: Tuesday, 18 September 2018 at 07:55
To: <[email protected]>
Subject: How to use ORDER BY in a query built by the ARQ API?

 

Hello everyone, 

how is it possible to build a query like: 
SELECT DISTINCT  * WHERE
  { 
    ?s  skos:broader  ?o

  } 

ORDER BY ?s

 

with the Jena ARQ API (org.apache.jena.sparql.syntax.*)

 

The first part would be achieved by: 

 

final ElementTriplesBlock baseCriteria = new ElementTriplesBlock();
baseCriteria.addTriple(

     new Triple(

         Var.alloc("s"),

         NodeFactory.createURI("skos:broader"),

         Var.alloc("o")

     )

);

 

I can add this to an ElementGroup, but which Java Type shall be used to 
gernerate ORDER BY ?s ?

 

Thanks & Best Regards

Andreas 




Reply via email to