Unrolling SPARQL in SPARQL: Exploring SPARQL views as a declarative rewriting mechanism

Abstract

With the finalization of RDF 1.2 and SPARQL 1.2, the new triple-term construct brings native reification to RDF and narrows the long-standing gap with Property Graphs. Native support, however, does not imply uniform adoption: existing and new datasets continue to model statement-level metadata through established patterns, so federated queries must mediate between these patterns and the new triple-term syntax. We address this by rewriting queries written against triple terms into queries over the reification pattern actually used by the source, expressing the relationship between patterns and triple terms as a SPARQL CONSTRUCT query that is unfolded into the user’s query as a Global-As-View mapping. This paper demonstrates that approach through a web interface in which users author their own mappings, select sources, and observe how their queries are rewritten and executed across federated endpoints. Because both the mappings and the rewriting live entirely within SPARQL, the rewritten query runs on any standards-compliant SPARQL 1.2 federation engine, with no engine modification and with extensibility to reification schemes not foreseen at design time. This makes RDF 1.2 interoperability achievable today using only the query language practitioners already know, and reframes RDF-to-RDF mapping as a declarative, interpretable activity rather than a handwritten algorithm. Looking ahead, we plan to lift current restrictions, formalize and optimize our approach, and turn the language gaps we encounter into concrete input for the upcoming SPARQL maintenance-mode standardization. 3


Keywords Data Integration, Query Rewriting, SPARQL 1.2, RDF 1.2, Structural rewriting, Global-as-View

  3 Canonical version: https:/​/​2026-amw-rewriting.jitsedesmet.be/
AMW 2026: 17th Alberto Mendelzon International Workshop on Foundations of Databases and the Web, November 9th–13th, 2026, Arequipa, Peru jitse.desmet@ugent.be (J. De Smet); maxime.jakubowski@tuwien.ac.at (M. Jakubowski); ruben.taelman@ugent.be (R. Taelman) 0009-0002-6513-5013 (J. De Smet); 0000-0002-7420-1337 (M. Jakubowski); 0000-0001-5118-256X (R. Taelman) © 2026 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).

Introduction

With the finalization of the RDF 1.2 [1] and SPARQL 1.2 [2] specifications, data publishers and consumers gain access to the newly introduced triple term: a triple that may itself appear in the object position of another triple, allowing arbitrary nesting. This extension brings native reification to RDF and narrows the gap between RDF and Property Graphs [3]. The construct directly descends from RDF-star and SPARQL-star [4], proposed over a decade ago.

Native support, however, does not imply uniform adoption. Existing, and even new, datasets might choose to continue modelling statement-level metadata using established reification patterns: 1. rdf-reification, 2. singleton properties, 3. named graphs, 4. nn-ary relations, and 5. potentially the vocabulary proposed in the draft RDF 1.2 interoperability note [5]. SPARQL federation [6], which allows querying multiple datasets through a single query, must therefore mediate between these patterns and the new triple-term syntax of SPARQL 1.2.

We address this by rewriting queries written against triple terms into queries over the reification pattern actually used by the source. Our contribution is a generic rewriting approach in which the relationship between each reification scheme and triple terms is described by a standard SPARQL CONSTRUCT query. The CONSTRUCT body is then unfolded into the user’s query — no engine modification required. Although we focus on the triple-term-to-legacy direction motivated by the RDF 1.2 transition, the same mechanism applies to the general RDF-to-RDF mapping problem.

The next section reviews related work on mapping and rewriting for RDF. Section 3 describes our naive rewriting approach and it’s limitations. Section 4 presents the demonstration, and Section 5 concludes our paper.

Query rewriting

A GAV-style mapping has a body qSq_\mathcal{S}, a query over a source, and a head gg, an assertion to be made in the global. We write the mapping as gqSg \rightsquigarrow q_\mathcal{S}. In SPARQL CONSTRUCT, the template is the head and the WHERE clause is the body. When the template contains multiple triples patterns, we split the mapping into one rule per triple pattern and combine the rules through a UNION in the WHERE clause. Strictly speaking, only one mapping targets the global [7]; when several are provided, they are implicitly merged using dataset merge [8], although for query evaluation we use bag-union rather than the more expensive set-union. Fig. 1 shows two example mappings expressed as CONSTRUCT queries, and Fig. 2 shows their combination into a single rule with one triple pattern in the head.

Algorithm. The rewriting algorithm unfolds each triple pattern in the user query against any mapping whose head matches it. When the triple pattern carries additional constraints, those constraints are pushed into the body of the mapping. The first triple pattern of Fig. 3, for example, fixes the predicate to rdf:reifies and the object to a triple term whose inner predicate is rdf:type; these constants flow into the unfolded body, replacing ?p by rdf:type in Fig. 4. Mappings whose head cannot match the pattern, for instance because the predicates are incompatible, contribute a FILTER(FALSE) branch, which a downstream optimizer can prune.

# Create a mapping from rdf reification to triple terms
CONSTRUCT { ?t rdf:reifies <<( ?s ?p ?o )>> }
WHERE {
  ?t a rdf:Statement ; rdf:Subject ?s ;
     rdf:Predicate ?p ; rdf:Object ?o ; 
} # and copy all triples
CONSTRUCT { ?s ?p ?o } WHERE {
  ?s ?p ?o .
}

Fig. 1: Two mappings: one constructs triple terms in the global, the other passes source triples through unchanged.

CONSTRUCT { ?s ?p ?o } WHERE {
  { ?m_t a rdf:Statement ;
       rdf:Subject ?m_s ;
       rdf:Predicate ?m_p ;
       rdf:Object ?m_o .
    BIND(?m_t as ?s) .
    BIND(rdf:reifies as ?p) .
    BIND(triple(?m_s, ?m_p, ?m_o) as ?o). }
  UNION
  { ?s ?p ?o }
}

Fig. 2: The same global as Fig. 1, expressed as a single CONSTRUCT in accordance with Subsection 2.1.

SELECT * WHERE {
  ?t rdf:reifies <<( ?s rdf:type ?o )>> ;
     ex:confidence ?score .
  FILTER(?score > 0.8)
}

Fig. 3: Example user query: triple terms asserting rdf:type with a confidence score above 0.8.

SELECT ?score ?o ?s ?t WHERE {
  { ?t rdf:type rdf:Statement ; rdf:Subject ?s ;
       rdf:Predicate rdf:type ; rdf:Object ?o . }
  UNION { # Assume 1.1 sources -> no triple terms
    FILTER ( FALSE ) }
  { # Predicate rdf:reifies does not match ex:confidence
    FILTER ( FALSE ) }
  UNION { ?t ex:confidence ?score }
  FILTER ( ?score > 0.8 )
}

Fig. 4: Cleaned-up version (for readability) of the query in Fig. 3 rewritten against the mapping in Fig. 2. The rewritten query no longer asks the source for triple terms; instead it expresses the same intent through the reification scheme used by the source.

Limitations. Blank nodes are not supported in mapping queries. Both the template of a CONSTRUCT query and the BNODE expression introduce fresh blank nodes scoped to a single query solution, which would make the unfolded query unstable. We plan to support Skolemized blank nodes in future work.

Blank nodes in the sources are likewise unsupported. As in standard SPARQL federation when the same endpoint is queried more than once, blank nodes from a source cannot be matched across invocations, since blank nodes are scoped to the document or result set in which they are serialized [2]. Skolemization of the source is therefore a prerequisite.

User queries that use the recursive property path operators * and + are not supported. We expect that a recursive extension to SPARQL will be a prerequisite for handling them.

Demonstration

The demo lets users issue federated queries over sources of their choice, against a global schema that they define through their own mappings. The interface consists of four panels.

The mappings panel (top left) is where users manage the CONSTRUCT queries that together define the global schema. Formally, a GAV mapping is a single CONSTRUCT (see Subsection 2.1); the UI lets users write multiple mappings whose outputs are implicitly unioned.

The query panel (top right) is where users select sources and write the query. With no sources selected, the rewritten query can still return results when the mappings include SERVICE calls. When many sources are selected, the federation engine performs exhaustive source selection [20], which can itself be viewed as a second GAV rewriting in which every mapping has the form CONSTRUCT { ?s ?p ?o } WHERE { SERVICE <serviceA> { ?s ?p ?o } }. The panel also offers preset scenarios: 1. trustworthiness using RDF 1.2, 2. exhaustive source selection, and 3. spam-filter.

The rewritten query panel (bottom left) is read-only; after execution it shows the user query unfolded against the mappings.

The results panel (bottom right) reports elapsed execution time, the result count, and the streaming bindings as they arrive.

A screenshot of the demonstration webUI

Fig. 5: Screenshot of the web interface: a user query is rewritten against user-defined mappings and executed over the chosen sources.

Conclusion

We have presented a preliminary implementation of a generic framework for RDF 1.2 interoperability through query rewriting, and, more broadly, for declarative RDF-to-RDF mapping. The approach is declarative rather than imperative, a choice that buys 1. extensibility to reification schemes not foreseen at design time, 2. interpretable transformations, and 3. reuse of existing SPARQL skills.

The mappings are GAV rules expressed as SPARQL CONSTRUCT queries, and rewriting proceeds by unfolding those rules into the user’s query. Because both the rules and the rewriting live within SPARQL, the rewritten query runs on any standards-compliant SPARQL 1.2 federation engine. When a desired mapping cannot be expressed in standard SPARQL, the missing feature becomes concrete input for the upcoming maintenance-mode standardization of the language. We have already encountered a handful of candidates: a CONSTRUCT GRAPH form, syntactic sugar for triple-term templates, and recursive view definitions.

This is ongoing work; performance optimization and concrete language-extension proposals are the immediate next steps. Our aim with this demonstration is to draw attention to GAV-style SPARQL mappings, to showcase their use for RDF 1.2 interoperability, and to open discussion on the language features the community needs.

Acknowledgements

Jitse De Smet is a predoctoral fellow of the Research Foundation – Flanders (FWO) (1SB8525N).

Declaration on Generative AI

During the preparation of this work, the author(s) used Claude Opus 4.7 in order to: Paraphrase and reword, improve writing style, perform grammar and spelling checks, and critically review the text written by the authors to highlight essential information. After using these tool(s)/service(s), the author(s) reviewed and edited the content as needed and take(s)full responsibility for the publication’s content.