Skip to content

Data sources

A logical source names the data (rml:source), the query language (rml:referenceFormulation) and, for most formats, an iterator.

Format rml:referenceFormulation Module
JSON rml:JSONPath carml-logical-source-resolver-jsonpath
XML rml:XPath carml-logical-source-resolver-xpath
CSV rml:CSV carml-logical-source-resolver-csv
SQL rml:SQL2008Query, rml:SQL2008Table carml-logical-view-sql-mysql, carml-logical-view-sql-postgresql or carml-logical-view-duckdb

JSON and CSV files can also be read by the DuckDB evaluator. See Evaluators.

The legacy formulations ql:JSONPath, ql:XPath, ql:CSV and ql:Rdb are accepted too.

Where the data is

rml:source Reads from
rml:RelativePathSource with rml:path A file. See below for what the path is relative to.
dcat:Distribution The dcat:downloadURL, or else the dcat:accessURL. http, https and file URLs work.
carml:FileSource with carml:url A URL, or a file path. A relative path is resolved like an rml:path without rml:root.
csvw:Table The csvw:url, read with the table's CSVW dialect.
d2rq:Database A MySQL or PostgreSQL database.
carml:Stream An InputStream you pass in. See Extensions.

Relative paths

rml:root decides what rml:path is relative to:

  • No rml:root, or rml:CurrentWorkingDirectory: the working directory.
  • rml:MappingDirectory: the directory of the mapping file. This needs a mapping loaded from exactly one file path.

Without a base directory, an absolute rml:path is used as it is. In the library, fileResolver(Path) and classPathResolver(String) on the builder override rml:root, and in the CLI -rsl does.

Compression and encoding

rml:compression on a source can be rml:gzip, rml:zip, rml:targz or rml:tarxz. From an archive CARML reads the first entry. rml:encoding can be rml:UTF-8 or rml:UTF-16.

The DuckDB evaluator reads UTF-8 files that are uncompressed, and gzip-compressed CSV files. It leaves other sources to the reactive evaluator, which handles all of these.

JSON

rml:logicalSource [ a rml:LogicalSource ;
    rml:source [ a rml:RelativePathSource ; rml:path "people.json" ] ;
    rml:referenceFormulation rml:JSONPath ;
    rml:iterator "$.people[*]" ] .

For a newline-delimited JSON (NDJSON) file with one object on each line, use iterator $. Each line is one record.

XML

rml:logicalSource [ a rml:LogicalSource ;
    rml:source [ a rml:RelativePathSource ; rml:path "books.xml" ] ;
    rml:referenceFormulation rml:XPath ;
    rml:iterator "/bookstore/book" ] .

To use namespace prefixes in XPath expressions, declare them on the reference formulation:

rml:logicalSource [ a rml:LogicalSource ;
    rml:source [ a rml:RelativePathSource ; rml:path "books.xml" ] ;
    rml:referenceFormulation [ a rml:XPathReferenceFormulation ;
        rml:namespace [ a rml:Namespace ;
            rml:namespacePrefix "ex" ;
            rml:namespaceURL "http://www.example.com/books/1.0/" ] ] ;
    rml:iterator "/ex:bookstore/*" ] .

CSV

rml:logicalSource [ a rml:LogicalSource ;
    rml:source [ a rml:RelativePathSource ; rml:path "cars.csv" ] ;
    rml:referenceFormulation rml:CSV ] .

Each row is a record and references are column names. There is no iterator.

An empty cell is an empty string, not a missing value. rml:null on the source names the strings to treat as missing, so that they produce no triple:

rml:source [ a rml:RelativePathSource ; rml:path "cars.csv" ; rml:null "" ] ;

SQL databases

Describe the connection as a d2rq:Database. Put the query in rml:iterator:

@prefix rml:  <http://w3id.org/rml/> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .

<#Students> a rml:LogicalSource ;
  rml:source <#DB> ;
  rml:referenceFormulation rml:SQL2008Query ;
  rml:iterator "SELECT name FROM student" .

<#DB> a d2rq:Database ;
  d2rq:jdbcDSN    "jdbc:postgresql://localhost:5432/db" ;
  d2rq:jdbcDriver "org.postgresql.Driver" ;
  d2rq:username   "postgres" ;
  d2rq:password   "" .

With rml:SQL2008Table, rml:iterator holds a table name and CARML runs SELECT * FROM that table.

The R2RML properties rr:sqlQuery and rr:tableName still work in legacy mappings.

MySQL and PostgreSQL are supported. Which component talks to the database depends on the evaluator. The native SQL evaluator sends the query, joins included, to the database. The DuckDB evaluator attaches the database and runs the joins itself.