d2rq/d2rq — Issue #109: Query-based class maps
Author: cygri
Created: 2012-03-06 23:30:14+00:00
State: open
Labels: expressivity, R2RML, usability

A query-based class map is based on a SQL query, rather than on one or more tables. It is similar to making a class map based on a SQL view. This is a stepping stone towards R2RML support – this query-based approach features prominently in that language.

map:Authors a d2rq:ClassMap;
d2rq:query """
SELECT AUTHOR.ID, (FIRST || ' ' || LAST) AS NAME, COUNT(POST.ID)
FROM AUTHOR, POST
WHERE POST.AUTHOR_ID=AUTHOR.ID
""";
d2rq:uriPattern "author/@@ID@@";
d2rq:class ex:Author.
map:AuthorsName a d2rq:PropertyBridge;
d2rq:belongsToClassMap map:Authors;
d2rq:property ex:creator;
d2rq:column "NAME".

The columns referenced in the `d2rq:uriPattern` and `d2rq:column` are named columns in the query result. Note that they are not table-qualified, unlike elsewhere in D2RQ.

Other relation properties, like `d2rq:condition`, `d2rq:alias` and `d2rq:join`, should not be allowed on such a class map and its property bridges, with the possible exception of `d2rq:join` and `d2rq:alias` on a property bridge that has `d2rq:refersToClassMap`.

The easiest (and non-optimized) way to implement this in the SQL rewriter is by using a SQL subquery. Internally it could be treated like a pseudo-table with a random internal name. The column references would internally be translated to something like `QUERY1.ID` and `QUERY1.NAME`. The `Relation` object would have to know that `QUERY1` is a subquery name for the full SQL query.