Copyright © 2010 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
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.
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. The Working Group is also working on a document that will define a default mapping from relational databases to RDF. The Working Group hopes to publish the default mapping document shortly.
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.
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
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)
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”.
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:
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.
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.
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:
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.
In this document, examples assume the following namespace prefix bindings unless otherwise stated:
Prefix | IRI |
---|---|
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
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.
Column Name | Column Datatype | Column Key Constraints |
---|---|---|
deptno | INTEGER | UNIQUE |
dname | VARCHAR(30) | |
loc | VARCHAR(100) |
deptno | dname | loc |
---|---|---|
10 | APPSERVER | NEW YORK |
Content of the logical table defined as follows is shown below:
Select ('_:Department' || deptno) AS deptId , deptno , dname , loc from dept;
deptId | deptno | dname | loc |
---|---|---|---|
_:Department10 | 10 | APPSERVER | NEW YORK |
Column Name | Column Datatype | Column Key Constraint |
---|---|---|
empno | INTEGER | PRIMARY KEY |
ename | VARCHAR(100) | |
job | VARCHAR(30) | |
deptno | INTEGER | REFERENCES DEPT(deptno) |
etype | VARCHAR(30) |
empno | ename | job | deptno | etype |
---|---|---|---|---|
7369 | SMITH | CLERK | 10 | PART_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;
empURI | empno | ename | jobTypeURI | job | deptno | empTypeURI | etype | graphURI |
---|---|---|---|---|---|---|---|---|
<xyz.com/emp/7369> | 7369 | SMITH | <xyz.com/emp/job/CLERK> | CLERK | 10 | <xyz.com/emp/etype/PART_TIME> | PART_TIME | <xyz.com/graph/CLERK/PART_TIME> |
Column Name | Column Datatype | Column Key Constraint |
---|---|---|
id | VARCHAR(4000) | |
likeType | VARCHAR(30) | |
likedObj | VARCHAR(100) |
id | likeType | likedObj |
---|---|---|
7369 | Playing | Soccer |
7369 | Watching | Basketball |
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;
empId | empLikes | likedObj |
---|---|---|
<xyz.com/emp/7369> | <xyz.com/emp/likes/Playing> | Soccer |
<xyz.com/emp/7369> | <xyz.com/emp/likes/Watching> | Basketball |
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.
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.
This section defines the RDF properties that have the RDFTermMap class as their domain.
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 .
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")
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")
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.).
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.
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" .
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")
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" .
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>)
This section describes the subclasses of the RDFTermMap class. These classes comprise specialized RDF term mappings namely to IRIs, blank nodes, and literals.
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 .
The IRIMap class represents the mapping to a RDF Resource.
rr:IRIMap rdfs:subClassOf rr:IRIorBlankNodeMap .
The BlankNodeMap class represents the mapping to a RDF blank node.
rr:BlankNodeMap rdfs:subClassOf rr:IRIorBlankNodeMap .
The LiteralMap class represents the mapping to a RDF literal.
rr:LiteralMap rdfs:subClassOf rr:RDFTermMap .
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.
This section defines the RDF properties that have the TriplesMap class as their domain.
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.
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>
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")
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 .
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
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>
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"; ];
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.
This section defines the RDF properties that have the ForeignKey class as their domain.
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 .
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 .
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" .
In this section we show an example relational schema and then map the example schema to RDF using the Turtle syntax.
We illustrate our example with the use of the following three relational tables, along with sample data.
Column Name | Column Datatype | Column Key Constraints |
---|---|---|
deptno | INTEGER | UNIQUE |
dname | VARCHAR(30) | |
loc | VARCHAR(100) |
deptno | dname | loc |
---|---|---|
10 | APPSERVER | NEW YORK |
Column Name | Column Datatype | Column Key Constraint |
---|---|---|
empno | INTEGER | PRIMARY KEY |
ename | VARCHAR(100) | |
job | VARCHAR(30) | |
deptno | INTEGER | REFERENCES DEPT(deptno) |
etype | VARCHAR(30) |
empno | ename | job | deptno | etype |
---|---|---|---|---|
7369 | SMITH | CLERK | 10 | PART_TIME |
Column Name | Column Datatype | Column Key Constraint |
---|---|---|
id | VARCHAR(4000) | |
likeType | VARCHAR(30) | |
likedObj | VARCHAR(100) |
id | likeType | likedObj |
---|---|---|
7369 | Playing | Soccer |
7369 | Watching | Basketball |
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:
Prefix | IRI |
---|---|
emp: | http://www.example.com/emp# |
dept: | http://www.example.com/dept# |
likes: | http://www.example.com/likes# |
<#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:
deptId | deptno | dname | loc |
---|---|---|---|
_:Department10 | 10 | APPSERVER | NEW 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.
Graph | Subject | Predicate | Object |
---|---|---|---|
xyz:DeptGraph | _:Department10 | rdf:type | xyz:dept |
xyz:DeptGraph | _:Department10 | dept:deptno | 10^^xsd:positiveInteger |
xyz:DeptGraph | _:Department10 | dept:name | "APPSERVER" |
xyz:DeptGraph | _:Department10 | dept:location | "NEW YORK" |
xyz:DeptGraph | _:Department10 | dept:COMPANY | "XYZ Corporation" |
<#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:
empURI | empno | ename | jobTypeURI | job | deptno | empTypeURI | etype | graphURI |
---|---|---|---|---|---|---|---|---|
<xyz.com/emp/7369> | 7369 | SMITH | <xyz.com/emp/job/CLERK> | CLERK | 10 | <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).
Graph | Subject | Predicate | Object |
---|---|---|---|
<xyz.com/graph/CLERK/PART_TIME> | <xyz.com/emp/7369> | rdf:type | xyz: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.
Graph | Subject | Predicate | Object |
---|---|---|---|
emp:empNameGraph | <xyz.com/emp/7369> | emp:name | "SMITH" |
<#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:
empId | empLikes | likedObj |
---|---|---|
<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.
Graph | Subject | Predicate | Object |
---|---|---|---|
xyz:LikesGraph | <xyz.com/emp/7369> | <xyz.com/emp/likes/Playing> | "Soccer" |
xyz:LikesGraph | <xyz.com/emp/7369> | <xyz.com/emp/likes/Watching> | "Basketball" |
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.
$Log: Overview.html,v $ Revision 1.6 2018/10/09 13:23:24 denis fix validation of xhtml documents Revision 1.5 2017/10/02 10:42:03 denis add fixup.js to old specs Revision 1.4 2010/10/28 15:30:16 hhalpin updated Revision 1.3 2010/10/28 14:39:13 hhalpin add two sentences to deal with default mapping resulting from W3C telecon. Revision 1.2 2010/10/27 14:41:44 hhalpin Removed e-mails of editors for their own safety Revision 1.1 2010/10/27 13:58:07 hhalpin First FPWD 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