Skip to main content
Back to Standards

R2RML: RDB to RDF Mapping Language

R2RML

A W3C Recommendation that defines a language for expressing customized mappings from relational databases to RDF datasets. R2RML mappings are themselves RDF graphs written in Turtle syntax, specifying how each table or view in a relational database maps to RDF triples. The language supports complex transformations including joins, computed columns, and datatype assignments, enabling existing relational data to be exposed as a virtual or materialized RDF graph without modifying the source database.

Overview

R2RML is a W3C Recommendation that provides a language for expressing customized mappings from relational databases to RDF. It allows data architects to define precisely how tables, columns, and rows in a relational database should be transformed into RDF triples, enabling existing enterprise data to participate in the linked data ecosystem without requiring changes to the source database.

Background

By the early 2010s, the Semantic Web had mature specifications for representing and querying RDF data, but the vast majority of the world's structured data remained locked in relational databases. While the W3C's Direct Mapping specification provided a default mechanical translation from relational schemas to RDF, real-world needs demanded customizable mappings where database columns could be mapped to specific ontology properties, URIs could be constructed from column values, and data from multiple tables could be combined into coherent RDF graphs. The W3C RDB2RDF Working Group developed R2RML to address this, publishing it as a W3C Recommendation on 27 September 2012.

Purpose & Scope

An R2RML mapping is itself an RDF graph, typically written in Turtle syntax. It consists of one or more triples maps, each describing how data from a logical table (a base table, view, or SQL query) should be transformed into RDF triples. Each triples map contains a subject map and one or more predicate-object maps.

Key constructs in R2RML include:

Construct Purpose
rr:TriplesMap Top-level mapping unit connecting a logical table to RDF output
rr:logicalTable Specifies the source table, view, or SQL query
rr:subjectMap Defines how to generate the subject URI or blank node
rr:predicateObjectMap Pairs a predicate with an object map
rr:template A URI template with column references for constructing IRIs
rr:joinCondition Enables joins between logical tables within a mapping

R2RML supports both materialization (generating an RDF dump) and virtualization (translating SPARQL queries to SQL on the fly), depending on the processor implementation.

Governance & Maintenance

R2RML was developed by the W3C RDB2RDF Working Group and published alongside the Direct Mapping specification. Both are W3C Recommendations. The specification includes a comprehensive test suite for verifying processor conformance.

Notable Implementations

Several R2RML processors are available, including Morph-RDB, D2RQ (with R2RML support), Ontop (a virtual knowledge graph system), and the R2RML Parser. Ontop has gained particular prominence in enterprise settings for providing virtual RDF access over relational databases without materialization.

Related Standards

  • Direct Mapping -- The companion W3C Recommendation defining a default, non-customizable mapping from relational schemas to RDF
  • RML (RDF Mapping Language) -- An extension of R2RML that generalizes mappings beyond relational databases to CSV, JSON, and XML sources
  • SPARQL -- The query language used to access virtualized R2RML-mapped data

Further Reading