ConceptioArchiveW3C TR
W3C TRopen access

sparql11 federated query

W3C · w3c_tr
W3C TR · Standards · License: Open Access
Open Source ↗
w3c, standard

SPARQL 1.1 Federated Query @import url("local.css");

code { font-family: monospace; }

div.constraint, div.issue, div.note, div.notice { margin-left: 2em; }

ol.enumar { list-style-type: decimal; } ol.enumla { list-style-type: lower-alpha; } ol.enumlr { list-style-type: lower-roman; } ol.enumua { list-style-type: upper-alpha; } ol.enumur { list-style-type: upper-roman; }

div.exampleInner pre { margin-left: 1em; margin-top: 0em; margin-bottom: 0em} div.exampleOuter {border: 4px double gray; margin: 0em; padding: 0em} div.exampleInner { background-color: #d5dee3; border-top-width: 4px; border-top-style: double; border-top-color: #d3d3d3; border-bottom-width: 4px; border-bottom-style: double; border-bottom-color: #d3d3d3; padding: 4px; margin: 0em } div.exampleWrapper { margin: 4px } div.exampleHeader { font-weight: bold; margin: 4px}

em.rfc2119 { text-transform: lowercase; font-variant: small-caps; font-style: normal; } This version: http://www.w3.org/TR/2013/REC-sparql11-federated-query-20130321/ Latest version: http://www.w3.org/TR/sparql11-federated-query/ Previous version: http://www.w3.org/TR/2012/PR-sparql11-federated-query-20121108/ Editors: Eric Prud'hommeaux, W3C <[email protected]> Carlos Buil-Aranda, Ontology Engineering Group, UPM, Spain; currently at Universidad Pontificia Católica de Chile Contributors: Andy Seaborne, The Apache Software Foundation Axel Polleres, Siemens AG <[email protected]> Lee Feigenbaum, Cambridge Semantics <[email protected]> Gregory Todd Williams, Rensselaer Polytechnic Institute <[email protected]> Please refer to the errata See also translations Copyright W3C ® MIT ERCIM Keio Beihang liability trademark document use RDF is a directed, labeled graph data format for representing information in the Web. SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. This specification defines the syntax and semantics of SPARQL 1.1 Federated Query extension for executing queries distributed over different SPARQL endpoints. The SERVICE May Be Superseded This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index Set of Documents This document is one of eleven SPARQL 1.1 Recommendations produced by the SPARQL Working Group SPARQL 1.1 Overview SPARQL 1.1 Query Language SPARQL 1.1 Update SPARQL1.1 Service Description SPARQL 1.1 Federated Query SPARQL 1.1 Query Results JSON Format SPARQL 1.1 Query Results CSV and TSV Formats SPARQL Query Results XML Format (Second Edition) SPARQL 1.1 Entailment Regimes SPARQL 1.1 Protocol SPARQL 1.1 Graph Store HTTP Protocol No Substantive Changes There have been no substantive changes to this document since the previous version change log color-coded diff Please Send Comments Please send any comments to [email protected] public archive SPARQL Working Group errata [email protected] public archive Endorsed By W3C This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web. Patents This document was produced by a group operating under the 5 February 2004 W3C Patent Policy public list of any patent disclosures Essential Claim(s) section 6 of the W3C Patent Policy 1 Introduction Document Conventions Namespaces Result Descriptions Terminology SPARQL 1.1 Federated Query Extension Simple query to a remote SPARQL endpoint SPARQL query with OPTIONAL to two remote SPARQL endpoints Service Execution Failure Interplay of SERVICE and VALUES (Informative) SPARQL 1.1 Simple Federation Extension: semantics Translation to the SPARQL Algebra SPARQL 1.1 Simple Federation Extension Algebra SERVICE Examples SERVICE Variables (Informative) Conformance Security Considerations (Informative) A References Normative References Other References Acknowledgements CVS History (Last Call and after) The growing number of SPARQL query services offer data consumers an opportunity to merge data distributed across the Web. This specification defines the syntax and semantics of the SERVICE This document uses the same namespaces as from the SPARQL 1.1 Query document Result sets are illustrated in tabular form as in the SPARQL 1.1 Query document x y z "Alice" <http://example/a> A 'binding' is a pair ( variable RDF term x y z x "Alice" y http://example/a z The following terms are defined in SPARQL 1.1 Query Language [SQRY] IRI RDF URI reference Solution Mapping Solution Sequence The SERVICE SERVICE This example shows how to query a remote SPARQL endpoint and join the returned data with the data from the local RDF Dataset. Consider a query to find the names of the people we know. Data about the names of various people is available at the http://people.example.org/sparql @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people15 foaf:name "Alice" . :people16 foaf:name "Bob" . :people17 foaf:name "Charles" . :people18 foaf:name "Daisy" . http://example.org/myfoaf.rdf <http://example.org/myfoaf/I> <http://xmlns.com/foaf/0.1/knows> <http://example.org/people15> . Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name FROM <http://example.org/myfoaf.rdf> WHERE { <http://example.org/myfoaf/I> foaf:knows ?person . SERVICE <http://people.example.org/sparql> { ?person foaf:name ?name . } } This query, on the data above, has one solution: Query Result: name "Alice" Imagine we want to query people and optionally obtain their interests and the names of people they know. Imagine for instance, two endpoints containing data about people: Data in the default graph at remote SPARQL endpoint: http://people.example.org/sparql @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people15 foaf:name "Alice" . :people16 foaf:name "Bob" . :people17 foaf:name "Charles" . :people17 foaf:interest <http://www.w3.org/2001/sw/rdb2rdf/> . and data in the default graph the remote SPARQL endpoint: http://people2.example.org/sparql @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :people15 foaf:knows :people18 . :people18 foaf:name "Mike" . :people17 foaf:knows :people19 . :people19 foaf:name "Daisy" . Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?person ?interest ?known WHERE { SERVICE <http://people.example.org/sparql> { ?person foaf:name ?name . OPTIONAL { ?person foaf:interest ?interest . SERVICE <http://people2.example.org/sparql> { ?person foaf:knows ?known . } } } } This query, on the data above, has three solutions: Query Result: person interest known "Alice" "Bob" "Charles" <http://www.w3.org/2001/sw/rdb2rdf/> <http://example.org/people19> Notice that in the query above there is a nested SERVICE OPTIONAL http://people.example.org/sparql The execution of a SERVICE SERVICE SERVICE SILENT SILENT SERVICE In the following query the SILENT SILENT Data in <http://people.example.org/sparql> <http://example.org/people15> <http://xmlns.com/foaf/0.1/name> "Charles" . Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { SERVICE SILENT <http://people.example.org/sparql> { <http://example.org/people15> foaf:name ?name . } } Query result if an error occurs while querying the remote SPARQL endpoint: name SPARQL 1.1 Query includes the VALUES VALUES VALUES The following example shows how SERVICE VALUES http://example.org/sparql Data in the default graph: @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :a a foaf:Person ; foaf:name "Alan" ; foaf:mbox; "[email protected]" . :b a foaf:Person ; foaf:name "Bob" ; foaf:mbox "[email protected]" . and data in the default graph the remote SPARQL endpoint http://example.org/sparql @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix : <http://example.org/> . :a foaf:knows :b . :b foaf:knows :c . :c foaf:knows :a . :a foaf:interest "SPARQL 1.1 Basic Federated Query" . :b foaf:interest "SPARQL 1.1 Query" . :c foaf:interest "RDB2RDF Direct mapping" . Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?s { ?s a foaf:Person . SERVICE <http://example.org/sparql> {?s foaf:knows ?o } } When the original query is executed naively, with an unconstrained service call the endpoint may return more results than necessary. It may also happen that the SPARQL endpoint will not return all of them. Many existing SPARQL endpoints have restrictions in the number of results they return and may miss the ones matching subjects ?s Query: PREFIX : <http://example.org/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?s { ?s a foaf:Person } This query, on the data above, has two solutions: Query Result: s <http://example.org/a> <http://example.org/b> Next, dispatch to the remote endpoint <http://example.org/sparql> a constrained query with the solutions for ?s PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX : <http://example.org/> SELECT * {?s foaf:knows ?o } VALUES (?s) { (:a) (:b) } The query process involving SERVICE Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?s ?o { ?s a foaf:Person SERVICE <http://example.org/sparql> {?s foaf:knows ?o } } This query, on the data above using VALUES Query Result: s o <http://example.org/a> <http://example.org/b> <http://example.org/b> <http://example.org/c> The SERVICE Transform (syntax form) If the form is GroupGraphPattern From the Translate Graph Patterns section SPARQL 1.1 Query Language SERVICE Let FS := the empty set Let G := the empty pattern, Z, a basic graph pattern which is the empty set. Let SilentOp := boolean, indicating SERVICE error behavior.

For each element E in the GroupGraphPattern If E is of the form FILTER(expr) FS := FS ∪ {expr} End

If E is of the form OPTIONAL{P} Let A := Transform(P) If A is of the form Filter(F, A2) G := LeftJoin(G, A2, F) Else G := LeftJoin(G, A, true) End End

If E is of the form MINUS{P} G := Minus(G, Transform(P)) End

If E is of the form BIND(expr AS var) G := Extend(G, var, expr) End

If E is any other form Let A := Transform(E) G := Join(G, A) End If E is of the form SERVICE [SILENT] IRI {P} Let G := Join(G, Service(IRI, Transform(P), SilentOp)) End The evaluation of SERVICE SPARQL Results RESULTS SPROT Definition: Evaluation of a Service Pattern iri be an IRI, Ω 0 SilentOp be a boolean variable to indicate that SERVICE execution should ignore errors when true. then: eval(D(G), Service(IRI,P,SilentOp)) = Invocation( iri, P, SilentOp ) the multiset of solution mappings corresponding to the results of executing query SELECT * WHERE Q Ω 0 error. In the folowing section we introduce two examples showing the evaluation of SERVICE Example: a SERVICE ... WHERE { { ?s :p1 ?v1 } SERVICE <srvc> {?s :p2 ?v2 } { ?s :p3 ?v2 } } Join( Service( <srvc>, Example: a SERVICE SILENT ... WHERE { { ?s :p1 ?v1 } SERVICE SILENT <srvc> {?s :p2 ?v2 } { ?s :p3 ?v2 } } Join( Service( <srvc>, In the this section we do not present official evaluation semantics for the SPARQL pattern SERVICE VAR SERVICE VAR A variable used in place of a service IRI indicates that the service call for any solution depends on that variable's binding in that solution. For instance, the default graph may contain data about which services contain data about project endpoints. We assume the following data on various projects that contains information about SPARQL endpoints where data about these projects (using the DOAP vocabulary @prefix void: <http://rdfs.org/ns/void#> . @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix doap: <http://usefulinc.com/ns/doap#> .

[] dc:subject "Querying RDF" ; void:sparqlEndpoint <http://projects1.example.org/sparql> . [] dc:subject "Querying RDF remotely" ; void:sparqlEndpoint <http://projects2.example.org/sparql> . [] dc:subject "Updating RDF remotely" ; void:sparqlEndpoint <http://projects3.example.org/sparql> . Data in the default graph at remote SPARQL endpoint http://projects2.example.org/sparql: _:project1 doap:name "Query remote RDF Data" . _:project1 doap:created "2011-02-12"^^xsd:date . _:project2 doap:name "Querying multiple SPARQL endpoints" . _:project2 doap:created "2011-02-13"^^xsd:date . Data in the default graph at remote SPARQL endpoint http://projects3.example.org/sparql: _:project3 doap:name "Update remote RDF Data" . _:project3 doap:created "2011-02-14"^^xsd:date . We now want to query the project names of projects on the subject "remote": PREFIX void: <http://rdfs.org/ns/void#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX doap: <http://usefulinc.com/ns/doap#>

SELECT ?service ?projectName WHERE { # Find the service with subject "remote". ?p dc:subject ?projectSubject ; void:sparqlEndpoint ?service . FILTER regex(?projectSubject, "remote")

# Query that service projects. SERVICE ?service { ?project doap:name ?projectName . } } In the following table we present the intuitive solutions for this query with the data above: Query Result: service title <http://projects2.example.org/sparql> "Query remote RDF Data" <http://projects2.example.org/sparql> "Querying multiple SPARQL endpoints" <http://projects3.example.org/sparql> "Update remote RDF Data" A SERVICE The query engine must determine the possible target SPARQL query services. The exact mechanism for doing this is not defined in this document. Execution order may also be used to determine the list of services to to be tried. The example above suggests a specific order of execution: evaluating the basic graph pattern and filter outside the SERVICE ?service SERVICE ?p dc:subject ?projectSubject ; void:sparqlEndpoint ?service FILTER regex(?projectSubject, "remote") Once ?service SERVICE ?service SERVICE ?service { ?project doap:name ?projectName . } Note that blank nodes are unique to any document which serializes them. Also, SERVICE SPROT See section 4 SPARQL 1.1 Federated Query Grammar SPARQL Query strings Definition of SERVICE SERVICE This specification is intended for use in conjunction with the SPARQL 1.1 Query Language SPARQL queries using SERVICE SPARQL Protocol 1.1 SPROT SPARQL 1.1 Query SQRY Uniform Resource Identifier (URI): Generic Syntax RFC3986 [SQRY] SPARQL 1.1 Query Language Latest version [SPROT] SPARQL 1.1 Protocol Latest version [CHARMOD] Character Model for the World Wide Web 1.0: Fundamentals, R. Ishida, F. Yergeau, M. J. Düst, M. Wolf, T. Texin, Editors, W3C Recommendation, 15 February 2005, http://www.w3.org/TR/2005/REC-charmod-20050215/ . Latest version [RFC3629] RFC 3629 UTF-8, a transformation format of ISO 10646, F. Yergeau November 2003 [RFC3986] RFC 3986 Uniform Resource Identifier (URI): Generic Syntax, T. Berners-Lee, R. Fielding, L. Masinter January 2005 [RFC3987] RFC 3987 [UNICODE] The Unicode Standard, Version 4. ISBN 0-321-18578-1, as updated from time to time by the publication of new versions. The latest version of Unicode and additional information on versions of the standard and of the Unicode Character Database is available at http://www.unicode.org/unicode/standard/versions/ [XML11] Extensible Markup Language (XML) 1.1, J. Cowan, J. Paoli, E. Maler, C. M. Sperberg-McQueen, F. Yergeau, T. Bray, Editors, W3C Recommendation, 4 February 2004, http://www.w3.org/TR/2004/REC-xml11-20040204/ . Latest version [BCP47] Best Common Practice 47, P. V. Biron, A. Malhotra, Editors, W3C Recommendation, 28 October 2004, http://www.rfc-editor.org/rfc/bcp/bcp47.txt . [RESULTS] SPARQL Query Results XML Format (Second Edition) Latest version [TURTLE] Turtle: Terse RDF Triple Language Latest version The SPARQL 1.1 Federated Query document is a product of the whole of the W3C SPARQL Working Group In addition, we have had comments and discussions with many people through the working group comments list. All comments go to making a better document. Carlos would also like to particularly thank Jorge Pérez, Oscar Corcho and Marcelo Arenas for their discussions on the syntax and semantics of the Federated query extension. Change Log Changes since Proposed Recommendation None Changes since Last Call Updated references, fix DOAP URL Changed the word "BINDINGS" to "VALUES" to match change in Query Specification.

Related documents

Record · ID 19471 · SHA-256 9f0ff4cb1ed2b6d2
Conceptio Open Knowledge Archive — every document is proof-bundled with source, license, and retrieval metadata.