ARQ - Basic Federated SPARQL Query

There are already ways to access remote RDF data. The simplest is to read a document which is an RDF graph and query it. Another way is with the SPARQL protocol which allows a query to be sent to a remote service endpoint and the results sent back (in RDF, or an XML-based results format or even a JSON one).

SERVICE is a feature of SPARQL 1.1 that allows an executing query to make a SPARQL protocol to another SPARQL endpoint.


PREFIX : <http://example/>
PREFIX  dc:     <>

FROM <mybooks.rdf>
  ?b dc:title ?title .
     { ?s dc:title ?title . ?s dc:creator ?a }


There is an operator in the algebra.

(prefix ((dc: <>))
  (project (?a)
      (BGP [triple ?b dc:title ?title])
      (service <>
            [triple ?s dc:title ?title]
            [triple ?s dc:creator ?a]

Performance Considerations

This feature is a basic building block to allow remote access in the middle of a query, not a general solution to the issues in distributed query evaluation. The algebra operation is executed without regard to how selective the pattern is. So the order of the query will affect the speed of execution. Because it involves HTTP operations, asking the query in the right order matters a lot. Don’t ask for the whole of a bookstore just to find a book whose title comes from a local RDF file - ask the bookshop a query with the title already bound from earlier in the query.

Controlling SERVICE requests.

The SERVICE operation in a SPARQL query may be configured via the Context. The values for configuration can be set in the global context (accessed via ARQ.getContext()) or in the per-query execution context.

The prefix srv: is the IRI <>.

Configuration from Jena version 3.1.1

Symbol Usage Default
srv:queryTimeout Set timeouts none
srv:queryCompression Enable use of deflation and GZip true
srv:queryClient Enable use of a specific client none
srv:queryContext Per-endpoint configuration none


As documented above.


Sets the flag for use of deflation and GZip.

Boolean: True indicates that gzip compressed data is acceptable.


Enable use of a specific client

Provides a slot for a specific HttpClient for use with a specific SERVICE


As documented above.

ARQ documentation index

Configuration for Jena version 3.0.0 through 3.1.0

Symbol Usage
srv:queryTimeout Set timeouts
srv:queryGzip Enable use of GZip
srv:queryDeflate Enable use of deflate
srv:queryAuthUser Basic authentication
srv:queryAuthPwd Basic authentication
srv:queryContext Per-endpoint configuration


Set the connect and read timeouts for the query.

If a timeout occurs a QueryExceptionHTTP is thrown. The cause of that exception will be a

Number: number of milliseconds for connect timeout.

String: number of milliseconds for connect timeout. If string is of the form “X,Y” the first number is the number of milliseconds for the connect timeout and the seconds is the number of milliseconds for the read timeout.

Connect timeout =0 read timeout = 0

Values of 0 indicate no timeout and service operation will wait until the remote server responds.


Sets the allow Gzip flag.

Boolean: True indicates that gzip compressed data is acceptable. false


Sets the allow Deflate flag.

Boolean: True indicates that deflate compression is acceptable False


Sets the user id for basic auth.

String: The user id to log in with

If null or null length no user id is sent.


Sets the password for basic auth.

String: The password to log in with.

If null or null length no password is sent.


Provides a mechanism to override system context settings on a per URI basis.

The value is a Map<String,Context> where the map key is the URI of the service endpoint, and the Context is a set of values to override the default values.

If a context is provided for the URI the system context is copied and the URI specific values are then copied in. This ensures that any URI specific settings will be used.