W3C

R2RML: RDB to RDF Mapping Language

W3C Working Draft 28 October 2010

This version:
http://www.w3.org/TR/2010/WD-r2rml-20101028/
Latest version:
http://www.w3.org/TR/r2rml/
Editors:
Souripriya Das, Oracle <souripriya.das@oracle.com>
Seema Sundara, Oracle <seema.sundara@oracle.com>
Richard Cyganiak, DERI, National University of Ireland, Galway <richard@cyganiak.de>

Abstract

This document describes R2RML, a language for expressing customized mappings from relational databases to RDF datasets. Such mappings provide the ability to view existing relational data in the RDF data model, expressed in a structure and target vocabulary of the mapping author's choice. R2RML mappings are themselves RDF graphs and written down in Turtle syntax. R2RML enables different types of mapping implementations: processors could, for example, offer a virtual SPARQL endpoint over the mapped relational data, or generate RDF dumps, or offer a Linked Data interface.

Status of this Document

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 at http://www.w3.org/TR/.

This is the First Public Working Draft of the "R2RML: RDB to RDF Mapping Language" for review by W3C members and other interested parties.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

The W3C RDB2RDF Working Group is responsible for this document. It includes the RDF Schema that can be used to specify a mapping of relational data to RDF. The structure of this document will change based upon future decisions taken by the W3C RDB2RDF Working Group.

Comments on this document should be sent to public-rdb2rdf-comments@w3.org, a mailing list with a public archive.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Introduction
    1.1 Terminology
    1.2 RDF-based Turtle Syntax; Media Type
    1.3 SQL Conformance
    1.4 Mapping Overview
    1.5 Document Conventions
2 Sample Relational Tables
    2.1 DEPT Table
    2.2 EMP Table
    2.3 LIKES Table
3 RDF Schema for R2RML
    3.1 RDFTermMap Class
        3.1.1 Properties of the RDFTermMap Class
            3.1.1.1 rr:property
            3.1.1.2 rr:column
            3.1.1.3 rr:propertyColumn
            3.1.1.4 rr:inverseExpression
            3.1.1.5 rr:datatype
            3.1.1.6 rr:language
            3.1.1.7 rr:columnGraphIRI and rr:columnGraph
            3.1.1.8 rr:constantValue
            3.1.1.9 rr:RDFTypeProperty
    3.2 Subclasses of RDFTermMap Class
        3.2.1 IRIorBlankNodeMap Class
        3.2.2 IRIMap Class
        3.2.3 BlankNodeMap Class
        3.2.4 LiteralMap Class
    3.3 TriplesMap Class
        3.3.1 Properties of the TriplesMap Class
            3.3.1.1 rr:logicalTable
            3.3.1.2 rr:subjectMap
            3.3.1.3 rr:propertyObjectMap
            3.3.1.4 rr:class
            3.3.1.5 rr:tableGraphIRI
            3.3.1.6 rr:rowGraph
            3.3.1.7 rr:foreignKeyMap
    3.4 ForeignKey Class
        3.4.1 Properties of the ForeignKey Class
            3.4.1.1 rr:key
            3.4.1.2 rr:parentTriplesMap
            3.4.1.3 rr:joinCondition

Appendices

A. Example of SQL based RDB2RDF Mapping using the Turtle Syntax (Informative)
    A.1 Sample Relational Tables
    A.2 Mapping Specification for the Tables
        A.2.1 Mapping Specification for the DEPT Table
        A.2.2 Mapping Specification for the EMP Table
        A.2.3 Mapping Specification for the LIKES Table
B. References
    B.1 Normative References
    B.2 Other References
C. Acknowledgements (Informative)
D. CVS History (Informative)


1 Introduction

This specification describes R2RML, a language for expressing customized mappings from relational databases to RDF datasets. Such mappings provide the ability to view existing relational data in the RDF data model, expressed in a structure and target vocabulary of the mapping author's choice.

Besides the R2RML language, this working group will also define a fixed “default mapping” from relational databases to RDF. In the default mapping of a database, the structure of the resulting RDF graph directly reflects the structure of the database, the target RDF vocabulary directly reflects the names of database schema elements, and neither structure nor target vocabulary can be changed. With R2RML on the other hand, a mapping author can define highly customized views over the relational data.

Every R2RML mapping is tailored to a specific database schema and target vocabulary. The input to an R2RML mapping is a relational database that conforms to that schema. The output is an RDF dataset [SPARQL], as defined in SPARQL, that uses predicates and type from the target vocabulary. The mapping is conceptual; R2RML processors are free to materialize the output data, or to offer virtual access through an interface that queries the underlying database, or to offer any other means of providing access to the output RDF dataset.

R2RML mappings are themselves expressed as RDF graphs and written down in Turtle syntax [TURTLE].

The intended audience of this specification are implementors of software that generates or processes R2RML mapping documents, as well as mapping authors looking for a reference to the R2RML language constructs. The document uses concepts from RDF Concepts and Abstract Syntax [RDF] and from the SQL language specifications [SQL1][SQL2]. A reader's familiarity with the contents of these documents, as well as with the Turtle syntax, is assumed.

The R2RML language is designed to meet the use cases and requirements identified in Use Cases and Requirements for Mapping Relational Databases to RDF [UCNR].

Unless otherwise noted in the section heading, all sections and appendices in this document are normative.

@@Issue: See ISSUE-5 for discussion of the default mapping.

@@Issue: The use of a “convention over configuration” approach has been proposed, where a mapping is not expressed completely, but rather as a delta from the default mapping. In other words, only those parts that one wants to be different from the default mapping have to be written down in the mapping file.

@@Issue: As currently defined, the output of an R2RML mapping is an RDF dataset that contains triples reflecting the records in the database. The output is thus on the “instance level”. A feature under discussion is the additional generation of an RDF Schema or OWL Ontology that reflects the constraints and valid inferences over the classes and properties in the generated dataset. This output would be on the “terminology level”.

1.1 Terminology

The following terms are defined in RDF Concepts and Abstract Syntax [RDF] and used in R2RML:

The following terms are defined in SPARQL Query Language for RDF [SPARQL] and used in R2RML:

1.2 RDF-based Turtle Syntax; Media Type

An R2RML mapping defines a mapping from a relational database to an RDF dataset. This mapping itself is represented as an RDF graph. In other words, RDF is used not just as the target data model of the mapping, but also as a formalism for representing the R2RML mapping itself. An RDF graph that represents an R2RML mapping is called a mapping graph.

An R2RML mapping document is any document written in the Turtle [TURTLE] RDF syntax that encodes an R2RML mapping graph. All examples throughout this specification use the Turtle syntax.

For R2RML mapping files, the same media type as for Turtle should be used: text/turtle. The preferred file extension is .ttl.

@@Issue: The current draft demands Turtle as the serialization format. What about other RDF formats, such as RDF/XML or RDFa?

@@Issue: The working group is considering alternative syntaxes, such as XML or a custom SPARQL-inspired syntax, in place of or in addition to Turtle, as the syntax for R2RML mapping documents, and seeks feedback on this issue.

1.3 SQL Conformance

R2RML mappings contain various database objects, such as table names, column names, and SQL queries. These references form an important part of the mapping. These SQL concepts are defined in ISO/IEC 9075-1:2008 [SQL1]. The syntax and semantics of SQL queries are defined in ISO/IEC 9075-2:2008 [SQL2].

In places where SQL expressions are allowed, these MUST conform to Core SQL 2008.

@@Issue: Implementors MUST be free to offer support for additional SQL dialects. How to address this?

The R2RML language is defined with reference to an execution environment that provides a SQL connection to the input database. The SQL connection MUST be established with sufficient privileges for read access to all base tables and views that are referenced in the R2RML mapping. How the SQL connection is established, or how users are authenticated against the database, is outside of the scope of this document. R2RML processors MAY use other means than evaluating SQL queries against the input database, as long as the results are the same.

@@Issue: For convenience reasons, connection details could be provided in the mapping file as well, rather than assuming that the connection must be configured externally.

@@Issue: The execution environment should probably provide other (optional) information besides the database connection, such as a base URI and default graph name.

1.4 Mapping Overview

An R2RML mapping consists of one or more structures called TriplesMaps.

Each TriplesMap contains a reference to a logical table in the input database. A logical table can be one of the following:

  1. A base table that exists in the input SQL schema.
  2. A view that exists in the input SQL schema.
  3. A valid SQL query against the input schema.

Furthermore, a TriplesMap contains a rule for mapping a logical table row to a set of RDF triples. The RDF triples generated from one row all share the same subject, defined by a structure called an RDFSubjectTermMap. The predicates and objects generated from the row are defined by RDFTermMaps, one per generated triple. The RDFTermMaps are rules for generating RDF nodes from the table row's values.

The output of an R2RML mapping is an RDF dataset. The RDF triples in the dataset are the result of applying the mapping rule of each TriplesMap to the rows of its logical table.

By default, all RDF triples are in the unnamed default graph of the RDF dataset. A TriplesMap can contain optional rules that place some or all of the triples into named graphs instead.

1.5 Document Conventions

In this document, examples assume the following namespace prefix bindings unless otherwise stated:

PrefixIRI
rr:http://www.w3.org/ns/r2rml#
rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs:http://www.w3.org/2000/01/rdf-schema#
xsd:http://www.w3.org/2001/XMLSchema#
xyz:http://example.com/ns#

Throughout the document, boxes containing Turtle markup and SQL data will appear. These boxes are color-coded. Gray boxes contain RDFS definitions of R2RML vocabulary terms:

# This box contains RDFS definitions of R2RML vocabulary terms

Yellow boxes contain example fragments of R2RML mappings in Turtle syntax:

# This box contains example R2RML mappings

Blue and green boxes contain example input and output data, respectively:

# This box contains example input tables
# This box contains example output RDF triples or fragments

2 Sample Relational Tables

This section shows a set of relational tables, and logical tables defined on them (via SQL queries), with sample data that will be used to illustrate the R2RML constructs introduced in the next section.

2.1 DEPT Table

Column NameColumn DatatypeColumn Key Constraints
deptnoINTEGERUNIQUE
dnameVARCHAR(30)
locVARCHAR(100)

deptnodnameloc
10APPSERVERNEW YORK

Content of the logical table defined as follows is shown below:

       Select ('_:Department' || deptno) AS deptId
            , deptno
            , dname
            , loc
         from dept;
deptIddeptnodnameloc
_:Department1010APPSERVERNEW YORK

2.2 EMP Table

Column NameColumn DatatypeColumn Key Constraint
empnoINTEGERPRIMARY KEY
enameVARCHAR(100)
jobVARCHAR(30)
deptnoINTEGERREFERENCES DEPT(deptno)
etypeVARCHAR(30)

empnoenamejobdeptnoetype
7369SMITHCLERK10PART_TIME

Content of the logical table defined as follows is shown below:

       Select ('<xyz.com/emp/' || empno||'>') AS empURI
            , empno
            , ename
            , ('<xyz.com/emp/job/'|| job||'>') AS jobTypeURI
            , job
            , deptno
            , ('<xyz.com/emp/etype/'|| etype||'>') AS empTypeURI
            , etype
            , ('<xyz.com/graph/'|| job || '/' || etype||'>') AS graphURI
       from emp;
empURIempnoenamejobTypeURIjobdeptnoempTypeURIetypegraphURI
<xyz.com/emp/7369>7369SMITH<xyz.com/emp/job/CLERK>CLERK10<xyz.com/emp/etype/PART_TIME>PART_TIME<xyz.com/graph/CLERK/PART_TIME>

2.3 LIKES Table

Column NameColumn DatatypeColumn Key Constraint
idVARCHAR(4000)
likeTypeVARCHAR(30)
likedObjVARCHAR(100)

idlikeTypelikedObj
7369PlayingSoccer
7369WatchingBasketball

Content of the logical table defined as follows is shown below:

      Select ('<xyz.com/emp/' || id||'>') AS empId
           , ('<xyz.com/emp/likes/' || likeType||'>') AS empLikes
           , likedObj
        from likes;
empIdempLikeslikedObj
<xyz.com/emp/7369><xyz.com/emp/likes/Playing>Soccer
<xyz.com/emp/7369><xyz.com/emp/likes/Watching>Basketball

3 RDF Schema for R2RML using Turtle Syntax

This section describes the RDF chema that can be used for specifying mapping from a relational schema to RDF. The RDF schema consists of two main classes: RDFTermMap Class and TriplesMap Class. Elements of the RDFTermMap class allows mapping values in a column to RDF (property, object) pairs. These elements appear only as values for properties of elements of the TriplesMap class. The (parent) TriplesMap class element for an RDFTermMap element completes the mapping to generate RDF (subject, property, object) triples by mapping each row in the (logical) table to an RDF subject and associating it to the (property, object) pairs obtained from column values in that row via RDFTermMap elements.

3.1 RDFTermMap Class

An element in the RDFTermMap class describes the mapping from the values in a column of a relational table to a collection of RDF (property, object) pairs, where the property name is an IRI specified by the user and the objects are obtained from the values in the specified column. The object can be any RDF term namely IRIs, blank nodes, or literals. This mapping description has two main components: 1) a user-specified RDF property and 2) the name of a column in the logical table that will be the source for the object values (to be associated with the property). For example, to map the content of the dname column in the logical table based on the DEPT table to the following

  (property=> dept:name, object=> "APPSERVER")
the RDFTermMap element should conceptually be the following:
  (property-name=> dept:name, object-column=> "dname")

Note that the association between the RDFTermMap element above and the DEPT table would be specified using a TriplesMap element and is not shown here.

It is not necessary that the property component of an RDFTermMap has to be a user-specified constant. Instead, like the object component, the property component too may be obtained from values in another specified column of the relational table. The values from that column are expected to be valid IRI references (so that they can be used as RDF properties). The property component of the mapping description in this case would be the name of a column in the logical table that will be the source for the property names. For example, to map the content of the empLikes and likedObj columns of the logical table based on the LIKES table to the following:

  (property-name=> <xyz.com/emp/likes/Playing>, object-column=> "Soccer")
  (property-name=> <xyz.com/emp/likes/Watching>, object-column=> "Basketball")
the RDFTermMap element should conceptually be the following:
  (property-column=> "empLikes", object-column=> "likedObj")

Note that the association between the RDFTermMap element above and the logical table based on the LIKES table would be specified using the TriplesMap element and is not shown here.

RDFTermMap

Figure 1: An RDF Graph describing the RDFTermMap class and its properties

3.1.1 Properties of the RDFTermMap Class

This section defines the RDF properties that have the RDFTermMap class as their domain.

3.1.1.1 rr:property
rr:property rdfs:range rdf:Property .

This property specifies the RDF property component of the RDFTermMap instance. The following example shows the property component of an RDFTermMap instance for the DEPT table.

 [] rr:property dept:name .
3.1.1.2 rr:column
rr:column rdfs:range xsd:string .

This property specifies the object value component of the RDFTermMap instance. Specifically, this property must be a column name in the logical table that will be used for obtaining the object value. In the following example, the dname column of the logical table defined using the DEPT table is specified as the source for the object component of an RDFTermMap instance and using rr:property, these objects are associated with the propery dept:name.

 [] rr:property dept:name; 
    rr:column "dname" .

Using the sample data for the DEPT table, the value "APPSERVER" in the dname column of the DEPT table, is mapped to the following (property, object) pair:

 (dept:name, "APPSERVER")
3.1.1.3 rr:propertyColumn
rr:propertyColumn rdfs:range xsd:string .

When the property name is not a constant and instead comes from the values in a column, this optional property (used in place of rr:property) allows the user to specify the column name. Note that this property should always be a column name in the logical table. Consider the following example based on the logical table defined using the LIKES table.

  [] rr:propertyColumn "empLikes";
     rr:column "likedObj".

Given the above TermMap definition and the sample data in the LIKES table, the generated (property, object) pairs are

       (<xyz.com/emp/likes/Playing>, "Soccer")
       (<xyz.com/emp/likes/Watching>, "Basketball")
3.1.1.4 rr:inverseExpression
rr:inverseExpression rdfs:range xsd:string .

This optional property specifies an expression that allows, at query processing time, use of indexes on any (underlying) relational table when accessing based on a value of a column (defined as an expression) in the logical table. The specified expression must be usable in the WHERE clause of a SQL query, with substitution of alias for the (logical) table associated with the parent TriplesMap class. Specifically, all the column names associated with the {alias.} must be actual column names in the associated logical table.

For example, for the deptId column in the logical table shown in Section 3.3.1.1, the inverse expression could be defined as follows:

"{alias.}deptno = substr({alias.}deptId,length('Department')+1)"

This facilitates the use of an index on the deptno column of the dept table. Note that the actual alias (say d) used for the dept table is used to expand {alias.} (to d.).

3.1.1.5 rr:datatype
rr:datatype rdfs:range rdfs:Datatype .

This optional property specifies the datatype for the object value component of the RDFTermMap instance. If not specified, the datatype for the object value will be derived from the column definition of the logical table. In the following example, the datatype of the object value component of an RDFTermMap instance is specified to be a positive integer.

[] rr:datatype xsd:positiveInteger .

If the datatype was not specified and the rr:column that was used is dept:deptno, then the rr:datatype property would become xsd:integer (based on DEPT table definiton), as if it was specified as follows:

[] rr:datatype xsd:integer .

If the rr:datatype is not specified and the database column is of a string type (such as VARCHAR), then the rr:datatype would be considered as an RDF plain literal.

3.1.1.6 rr:language
rr:language rdfs:range xsd:string .

This optional property specifies the language for the object value component of the RDFTermMap instance. This property is applicable only if the datatype of the object value is RDF plain literal. In the following example, the language tag for the object value component is specified to be US English.

[] rr:language "en-us" .
3.1.1.7 rr:columnGraphIRI and rr:columnGraph
rr:columnGraphIRI rdfs:range <Set of valid IRI references> .
rr:columnGraph rdfs:range xsd:string .

These two properties may be used to specify the RDF named graph for the triples that are constructed with the (property, object) pair of the RDFTermMap. The two properties differ as follows: the value for rr:columnGraphIRI must be a graph IRI, whereas the value for rr:columnGraph must be of a column of the logical table whose values will be used as the graph IRIs.

In the following example, the RDF named graph to be used for storing the triple generated using the (property, object) pair (emp:name, "ename") corresponding to an RDFTermMap is specified by the IRI emp:empNameGraph.

[] rr:property emp:name; 
   rr:column "ename"; 
   rr:columnGraphIRI emp:empNameGraph
.

Given the above mapping and the sample data in the EMP table, the emp:empNameGraph holds the triple containing the following (predicate, object) pair

      (emp:name, "SMITH")
3.1.1.8 rr:constantValue
rr:constantValue rdfs:range rdfs:Resource .

This property may be used in place of the rr:column property to specify a constant value for the object component of the RDFTermMap instance. The value can be any valid RDF term. In the following example, for the dept:COMPANY property of an RDFTermMap instance, the object value is specified as the plain literal "XYZ Corporation".

[] rr:property dept:COMPANY; 
   rr:constantValue "XYZ Corporation"
.
3.1.1.9 rr:RDFTypeProperty
rr:RDFTypeProperty rdfs:range xsd:string .

This property is the same as rr:property, but further indicates that any object value for this property is also the value of the rdf:type property. Object value for this property is expected to be a valid IRI. Consider the following example based on the logical table defined using the EMP table.

[] rr:RDFTypeProperty emp:emptype; 
   rr:column "empTypeURI" 
.

Given the above TermMap definition and the sample data in the EMP table, the generated (property, object) pairs are

       (emp:emptype, <xyz.com/emp/etype/PART_TIME>)
       (rdf:type,  <xyz.com/emp/etype/PART_TIME>)

3.2 Subclasses of the RDFTermMap Class

This section describes the subclasses of the RDFTermMap class. These classes comprise specialized RDF term mappings namely to IRIs, blank nodes, and literals.

Subclasses of the RDFTermMap

Figure 2: An RDF Graph describing the subclasses of the RDFTermMap class

3.2.1 IRIorBlankNodeMap

The IRIorBlankNodeMap class represents the mapping to any RDF term that can appear as subject of an RDF triple: IRIs or blank nodes.

rr:IRIorBlankNodeMap rdfs:subClassOf rr:RDFTermMap .

3.2.2 IRIMap

The IRIMap class represents the mapping to a RDF Resource.

rr:IRIMap rdfs:subClassOf rr:IRIorBlankNodeMap .

3.2.3 BlankNodeMap

The BlankNodeMap class represents the mapping to a RDF blank node.

rr:BlankNodeMap rdfs:subClassOf rr:IRIorBlankNodeMap .

3.2.4 LiteralMap

The LiteralMap class represents the mapping to a RDF literal.

rr:LiteralMap rdfs:subClassOf rr:RDFTermMap .

3.3 The TriplesMap Class

TriplesMap is an RDFS class that allows specification of a mapping of the rows in a logical table, represented by a SQL query, or the name of a table or view and its owner, into RDF triples. Properties of a TriplesMap instance allows specification of various aspects of the mapping such as, mapping of (some of) the columns in the logical table to RDF (property, object) pairs using RDFTermMap, name of the RDF graph(s) that would store the RDF triples, and so on.

TriplesMap

Figure 3: An RDF Graph describing the TriplesMap class and its properties

3.3.1 Properties of the TriplesMap Class

This section defines the RDF properties that have the TriplesMap class as their domain.

3.3.1.1 rr:logicalTable
rr:logicalTable rdfs:range xsd:String .

This property specifies the logical table (i.e., a valid SQL query or a table or view name plus its owner name) whose rows are mapped to RDF triples by this TriplesMap instance. Note that each row in the logical table is mapped to a resource which is used as the subject for the generated RDF triples describing the resource.

The following example specifies that the TriplesMap instance TriplesMap1 maps the rows in the logical table defined by the SQL query to RDF triples.

<#TriplesMap1> rr:logicalTable 
                                """Select 'Department' || deptno AS deptId
                                        , deptno
                                        , dname
                                        , loc
                                   from dept""" .

The cardinality of this property, for a TriplesMap instance, must be exactly 1. That is, a TriplesMap instance must have exactly one value for this property. Also, note that the logical table should not have duplicate column names or unnamed columns.

3.3.1.2 rr:subjectMap
rr:subjectMap  rdfs:range rr:IRIorBlankNodeMap .

This property specifies the mapping to obtain the IRI or blank node that is used as the subject of all the RDF triples generated from one row of the table. For rr:subjectMap, the default type is IRIMap. If the type is a blank node, then it must be explicitly specified using [a rr:BlankNodeMap]. In the following example, an IRIMap instance has been defined as the value for the subjectMap property of a TriplesMap instance for the logical table defined using the EMP table.

<#TriplesMap2> rr:subjectMap [ rr:column "empURI" ]

Using the above mapping definition, the obtained IRI for the single row in the sample data in the EMP table is

       <xyz.com/emp/7369>
3.3.1.3 rr:propertyObjectMap
rr:propertyObjectMap rdfs:range rr:RDFTermMap .

This property specifies the mapping to obtain the (property, object) pair for each RDF triple corresponding to a column and its values in the table. The following example shows a propertyObjectMap of a TriplesMap instance for the logical table defined using the DEPT table.

<#TriplesMap1> rr:propertyObjectMap [ rr:property dept:name; rr:column "dname" ] .

Using the above mapping and the sample data in the DEPT table, the value "APPSERVER" in the dname column of the logical table will be mapped to the following (predicate, object) pair.

        (dept:name, "APPSERVER")
3.3.1.4 rr:class
rr:class rdfs:range rdfs:Class .

This property specifies the RDFS class associated with a TriplesMap instance. In the generated RDF data, the resource corresponding to a row in the logical table will become an instance of this RDFS class.

In the following example, TriplesMap1 is associated with the RDFS class xyz:dept using the rr:class property. This leads to the creation of xyz:dept as an RDFS class in the RDFS schema generated from the mapping specification and in the generated RDF data, RDF resources being created for each row in the logical table associated with TriplesMap1 become instances of the xyz:dept class.

<#TriplesMap1> rr:class xyz:dept .

Given the above mapping and the sample data in the DEPT table, the following triple will be generated

       _:Department10 rdf:type xyz:dept .
3.3.1.5 rr:tableGraphIRI
rr:tableGraphIRI rdfs:range <Set of valid IRI references> .

This property specifies the graph IRI that would contain all the RDF triples in a TriplesMap instance.

Given the following example mapping,

<#TriplesMap1> rr:tableGraphIRI xyz:DeptGraph .

all the RDF triples in TriplesMap1 would be stored in the RDF named graph

 xyz:DeptGraph 
3.3.1.6 rr:rowGraph
rr:rowGraph rdfs:range xsd:string .

This optional property specifies the name of the column in the logical table that contains the RDF named graph for all the RDF triples generated from one row in the table. The minimum cardinality for this property is zero and no restriction on maximum cardinality. If for a row, value in the specified column is NULL, then the triples generated from that row go to an unnamed graph. If specified, the value of this property must be a column name in the logical table. In the following example, all the triples generated from a row of the logical table defined using the EMP table are stored in the RDF named graph identified by the IRI from the "graphURI" column of the logical table.

<#TriplesMap2> rr:rowGraph "graphURI" .

Given the above mapping and the sample data in the EMP table, the rows generated are stored in the RDF named graph

      <xyz.com/graph/CLERK/PART_TIME>
3.3.1.7 rr:foreignKeyMap
rr:foreignKeyMap rdfs:range rr:ForeignKey .

This property specifies the mapping to obtain the property, and a join condition that can be used to retrieve the object (from the parent Triples instance), for the generated RDF triple. This property would typically correspond to a foreign key definition in the table. The following example shows a foreignKeyMap for the logical table defined using the EMP table. See ForeignKey class for detailed explanation.

<#TriplesMap2> rr:foreignKeyMap [
      rr:key emp:c_ref_deptno;
      rr:parentTriplesMap xyz:dept;
      rr:joinCondition "{child.}deptno = {parent.}deptno";
    ];

3.4 The ForeignKey Class

ForeignKey is an RDFS class that allows specification of the mapping that describes a foreign key relationship.

rr:ForeignKey a rdfs:Class .

This class has three components: a key that specifies the column constraint in the child(referring) table, the TriplesMap corresponding to the parent(referenced) table, and the join condition corresponding to the foreign key constraint. Conceptually, a ForeignKey instance is similar to a propertyObjectMap where the property name is identified by the key and a join condition is specified that can be used to obtain the object value from the TriplesMap corresponding to the parent (logical) table.

ForeignKey

Figure 4: An RDF Graph describing the ForeignKey class and its properties

3.4.1 Properties of the ForeignKey Class

This section defines the RDF properties that have the ForeignKey class as their domain.

3.4.1.1 rr:key
rr:key rdfs:range rdf:Property .

This property specifies the constraint component of the ForeignKey instance. The following example identifies the IRI emp:c_ref_deptno as a property that represents a foreign key constraint.

[] rr:key emp:c_ref_deptno .
3.4.1.2 rr:parentTriplesMap
rr:parentTriplesMap rdfs:range rr:TriplesMap .

This property specifies the TriplesMap corresponding to the parent table component, of the ForeignKey instance. The following example identifies the TriplesMap corresponding to the parent logical table.

[] rr:parentTriplesMap xyz:dept .
3.4.1.3 rr:joinCondition
rr:joinCondition rdfs:range xsd:string .

This property specifies the join condition of the ForeignKey instance. The following example shows a join condition to be used to obtain the object values from the parent logical table.

[] rr:joinCondition "{child.}deptno = {parent.}deptno" .

A. Example of SQL based RDB2RDF Mapping using the Turtle Syntax (Informative)

In this section we show an example relational schema and then map the example schema to RDF using the Turtle syntax.

A.1 Sample Relational Tables

We illustrate our example with the use of the following three relational tables, along with sample data.

A.1.1 DEPT Table

Column NameColumn DatatypeColumn Key Constraints
deptnoINTEGERUNIQUE
dnameVARCHAR(30)
locVARCHAR(100)

deptnodnameloc
10APPSERVERNEW YORK

A.1.2 EMP Table

Column NameColumn DatatypeColumn Key Constraint
empnoINTEGERPRIMARY KEY
enameVARCHAR(100)
jobVARCHAR(30)
deptnoINTEGERREFERENCES DEPT(deptno)
etypeVARCHAR(30)

empnoenamejobdeptnoetype
7369SMITHCLERK10PART_TIME

A.1.3 LIKES Table

Column NameColumn DatatypeColumn Key Constraint
idVARCHAR(4000)
likeTypeVARCHAR(30)
likedObjVARCHAR(100)

idlikeTypelikedObj
7369PlayingSoccer
7369WatchingBasketball

A.2 Mapping Specification for the Tables

The tables specified in the above section are mapped to the RDF using the mapping specificied in this document. The table below the TriplesMap shows the insatnce-level RDF triples generated from the sample data in the tables. In addition to the prefix conventions specified in Section 1.4 Document Conventions
, we also use the following prefixes in our example:

PrefixIRI
emp:http://www.example.com/emp#
dept:http://www.example.com/dept#
likes:http://www.example.com/likes#

A.2.1 Mapping Specification for the DEPT Table

<#TriplesMap1>
    a rr:TriplesMap;
    rr:logicalTable "
       Select ('_:Department' || deptno) AS deptId
            , deptno
            , dname
            , loc
         from dept
       ";
    rr:class xyz:dept;
    rr:tableGraphIRI xyz:DeptGraph;
    rr:subjectMap [ a rr:BlankNodeMap; rr:column "deptId";
                    rr:InverseExpression "{alias.}deptno = substr({alias.}deptId,length('_:Department')+1)"];
    rr:propertyObjectMap [ rr:property dept:deptno; rr:column "deptno"; rr:datatype xsd:positiveInteger ];
    rr:propertyObjectMap [ rr:property dept:name; rr:column "dname" ];
    rr:propertyObjectMap [ rr:property dept:location; rr:column "loc" ];
    rr:propertyObjectMap [ rr:property dept:COMPANY; rr:constantValue "XYZ Corporation" ];
.

Content of the logical table used in this mapping:

deptIddeptnodnameloc
_:Department1010APPSERVERNEW YORK

The set of RDF triples generated using the above mapping:

The graph name for the following triples is generated using the rr:tableGraphIRI property.

GraphSubjectPredicateObject
xyz:DeptGraph_:Department10rdf:typexyz:dept
xyz:DeptGraph_:Department10dept:deptno10^^xsd:positiveInteger
xyz:DeptGraph_:Department10dept:name"APPSERVER"
xyz:DeptGraph_:Department10dept:location"NEW YORK"
xyz:DeptGraph_:Department10dept:COMPANY"XYZ Corporation"

A.2.2 Mapping Specification for the EMP Table

<#TriplesMap2>
    a rr:TriplesMap;
    rr:logicalTable "
       Select ('<xyz.com/emp/' || empno||'>') AS empURI
            , empno
            , ename
            , ('<xyz.com/emp/job/'|| job||'>') AS jobTypeURI
            , job
            , deptno
            , ('<xyz.com/emp/etype/'|| etype||'>') AS empTypeURI
            , etype
            , ('<xyz.com/graph/'|| job || '/' || etype||'>') AS graphURI
       from emp
       ";
    rr:class xyz:emp;
    rr:subjectMap [ rr:column "empURI" ];
		
    rr:rowGraph "graphURI";
		
    rr:propertyObjectMap [ rr:RDFTypeProperty emp:jobtype; rr:column "jobTypeURI" ];
    rr:propertyObjectMap [ rr:RDFTypeProperty emp:emptype; rr:column "empTypeURI" ];
		
    rr:propertyObjectMap [ rr:property emp:empno; rr:column "empno" ];
    rr:propertyObjectMap [ rr:property emp:name; rr:column "ename"; rr:columnGraphIRI emp:empNameGraph ];
    rr:propertyObjectMap [ rr:property emp:job; rr:column "job" ];
    rr:propertyObjectMap [ rr:property emp:deptNum; rr:column "deptno" ];
    rr:propertyObjectMap [ rr:property emp:etype; rr:column "etype" ];
    rr:foreignKeyMap [
      rr:key emp:c_ref_deptno;
      rr:parentTriplesMap xyz:dept;
      rr:joinCondition "{child.}deptno = {parent.}deptno";
    ];
    .

Content of the logical table used in this mapping:

empURIempnoenamejobTypeURIjobdeptnoempTypeURIetypegraphURI
<xyz.com/emp/7369>7369SMITH<xyz.com/emp/job/CLERK>CLERK10<xyz.com/emp/etype/PART_TIME>PART_TIME<xyz.com/graph/CLERK/PART_TIME>

The set of RDF triples generated using the above mapping (the two generated graphs are shown separately below):

The graph name for the following triples is generated using the rr:rowGraph property).

GraphSubjectPredicateObject
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>rdf:typexyz:emp
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:jobtype<xyz.com/emp/job/CLERK>
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:emptype<xyz.com/emp/etype/PART_TIME>
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:empno"7369"^^xsd:integer
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:name"SMITH"
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:job"CLERK"
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:deptNum"10"^^xsd:integer
<xyz.com/graph/CLERK/PART_TIME><xyz.com/emp/7369>emp:etype"PART_TIME"

The graph name for the following triple is generated using the rr:columnGraphIRI property.

GraphSubjectPredicateObject
emp:empNameGraph<xyz.com/emp/7369>emp:name"SMITH"

A.2.3 Mapping Specification for the LIKES Table

<#TriplesMap3>
    a rr:TriplesMap;
    rr:logicalTable "
      Select ('<xyz.com/emp/' || id||'>') AS empId
           , ('<xyz.com/emp/likes/' || likeType||'>') AS empLikes
           , likedObj
        from likes
      ";
    rr:tableGraphIRI xyz:LikesGraph;
    rr:subjectMap [ a rr:IRIMap; rr:column "empId"];
    rr:propertyObjectMap [ rr:propertyColumn "empLikes" rr:column "likedObj"]
    .

Content of the logical table used in this mapping:

empIdempLikeslikedObj
<xyz.com/emp/7369><xyz.com/emp/likes/Playing>Soccer
<xyz.com/emp/7369><xyz.com/emp/likes/Watching>Basketball

The set of RDF triples generated using the above mapping:

The graph name for the following triples is generated using the rr:tableGraphIRI property.

GraphSubjectPredicateObject
xyz:LikesGraph<xyz.com/emp/7369><xyz.com/emp/likes/Playing>"Soccer"
xyz:LikesGraph<xyz.com/emp/7369><xyz.com/emp/likes/Watching>"Basketball"

B. References

B.1 Normative References

[RDF]
Resource Description Framework (RDF): Concepts and Abstract Syntax, Graham Klyne, Jermey J. Carroll, Editors. World Wide Web Consortium, 10 February 2004. This version is http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/. The latest version is http://www.w3.org/TR/rdf-concepts/.
[SPARQL]
SPARQL Query Language for RDF, Eric Prud'hommeaux, Andy Seaborne, Editors. World Wide Web Consortium, 15 January 2008. This version is http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/. The latest version is http://www.w3.org/TR/rdf-sparql-query/.
[SQL1]
ISO/IEC 9075-1:2008 SQL – Part 1: Framework (SQL/Framework). International Organization for Standardization, 27 January 2009.
[SQL2]
ISO/IEC 9075-2:2008 SQL – Part 2: Foundation (SQL/Foundation). International Organization for Standardization, 27 January 2009.
[TURTLE]
Turtle - Terse RDF Triple Language, Dave Beckett, Tim Berners-Lee. World Wide Web Consortium, 14 January 2008. This version is http://www.w3.org/TeamSubmission/2008/SUBM-turtle-20080114/. The latest version is http://www.w3.org/TeamSubmission/turtle/.

B.2 Other References

[UCNR]
Use Cases and Requirements for Mapping Relational Databases to RDF, Eric Prud'hommeaux, Michael Hausenblas, Editors. World Wide Web Consortium, 8 June 2010. This version is http://www.w3.org/TR/2010/WD-rdb2rdf-ucr-20100608/. The latest version is http://www.w3.org/TR/rdb2rdf-ucr/. This document is work in progress.

C. Acknowledgements (Informative)

The editors gratefully acknowledge contributions from the members of the W3C RDB2RDF Working Group: Marcelo Arenas, Sören Auer, Samir Batla, Richard Cyganiak, Daniel Daniel Miranker, Souripriya Das, Alexander de Leon, Orri Erling, Ahmed Ezzat, Lee Feigenbaum, Angela Fogarolli, Enrico Franconi, Howard Greenblatt, Wolfgang Halb, Harry Halpin, Nuno Lopes, Li Ma, Ashok Malhotra, Ivan Mikhailov, Juan Sequeda, Seema Sundara, Ben Szekely, Edward Thomas, and Boris Villazón-Terrazas.

D. CVS History (Informative)

$Log: Overview.html,v $
Revision 1.5  2010/10/27 13:20:08  mhausenb
fixed expected pub date

Revision 1.4  2010/10/27 12:54:17  mhausenb
fix some minor things such as typos, pubrules now just complains re missing resources (but that's fine)

Revision 1.3  2010/10/27 12:42:04  mhausenb
fixing pubrules issues in SOTD section

Revision 1.2  2010/10/27 12:29:44  mhausenb
fix minor bug with CSS

Revision 1.1  2010/10/27 12:26:42  mhausenb
init FPWD R2RML as per WG decision http://www.w3.org/2010/10/19-rdb2rdf-minutes.html#item02 and http://www.w3.org/2010/10/26-rdb2rdf-minutes.html#item02