Theory — R2RML & rewriting
R2RML in one sentence
R2RML (W3C Recommendation) maps relational tables to RDF triples declaratively: each TriplesMap describes how rows in a logical table become subject IRIs, classes and predicate-object pairs.
Ontop reads the R2RML at startup, combines it with the ontology's TBox, and from that point on every incoming SPARQL query is rewritten — through unfolding and optimisation — into a single SQL query.
Why declarative matters
There is no code path between SPARQL and SQL in this design. No serialisers, no row-by-row transforms, no consumer to monitor. Wrong output ⇒ wrong mapping or wrong ontology, full stop. The blast radius of a bug is small enough to actually own.
The rewriting in action
A regulator asks (in SPARQL):
PREFIX : <https://atlas.example.com/onto/reporting/>
SELECT ?name WHERE {
?p a :HighRiskCounterparty ;
:legalName ?name .
}
Ontop unfolds this against the R2RML and emits roughly:
SELECT legal_name AS name
FROM dwh.party
WHERE is_active = TRUE
AND risk_tier = 'HIGH'
One SQL query. The warehouse planner does what it always does. The regulator gets fresh numbers, computed at query time.