d2rq/d2rq — Issue #113: Implement R2RML Natural Mapping of datatypes
Author: cygri
Created: 2012-03-07 00:15:30+00:00
State: open
Labels: priority, R2RML, usability

In D2RQ, when `d2rq:datatype` is not explicitly specified, then a plain literal is produced. In the W3C Direct Mapping and in R2RML, when the target datatype is not specified, then the [R2RML Natural Mapping](http://www.w3.org/TR/r2rml/#natural-mapping) is used. It automatically maps values to the closest XSD type, or to plain literals in the case of strings. This is nice for mapping authors because they don't need to write down all the target datatypes; they are inferred at runtime.

We should support this behaviour in D2RQ, as a stepping stone towards Direct Mapping and R2RML support. Perhaps enable it with a configuration option `d2rq:naturalDatatypeMapping true` on the `d2rq:Database`.

Implementation-wise, this means that the kind of `NodeMaker` to use for a column is inferred based on the column type if `d2rq:datatype` is absent. This would happen when a `ResourceMap` is turned into `TripleRelations`. For node makers where the datatype cannot be inferred at parse time (e.g., `d2rq:sqlExpression`), some `NaturalLiteralNodeMaker` would be used that defers the decision until we see the `ResultSet` from a query. This may imply changes to `ResultRowMap`, which currently sits between the `NodeMaker` and the `java.sql.ResultSet` and thus blocks access to the SQL type information.