Re: some r2rml questions

Juan, thanks for the reply. A translation table doesn't meet my need,
but after reading some of the WG discussion I can see how that might be
useful in r2rml.

The general problem is how to specify arbitrary transformations on
values returned from an SQL query. I think a general value-constructor
feature would be useful in r2rml. A translation table is one approach.
While the SQL CASE statement can do this, I can see why one might want
this logic in r2rml. 

My particular use case involves translating a large integer to a
dot-separated string of digits (like an IP address). The function uses
division, modulo, bit shifts, and concatenation. I think it can be done
in an SQL SELECT statement without recourse to custom functions, but I
gave up trying to get all the casts right (it took at least 3 nested
CASTs at last count). And even if I got it to work in one SQL dialect,
it probably wouldn't work in another (believe it or not I have the
opportunity to fetch the same data from SQL Server and Oracle).

So my custom solution was to add an xrr:columnValueConstructor predicate
to the TermMap where needed (where xrr: is an extension prefix).

It looks like there are at least three different ways that r2rml could
specify column value transformations:

1. Translation table, as was discussed by the WG.
2. By naming an external function id in the term map. The function id
would have to be registered with the r2rml processor somehow. (This
would be a more robust version of my quick-and-dirty solution)
3. By defining the function in r2rml. One way to do this in RDF would be
to use Lists to write s-expressions, using function names from xpath or
other specifications.

One of the reasons people will use r2rml is because they are more
comfortable with RDF and all the related standards than they are with
SQL, so even if some tasks could be done in SQL it would be good to have
more capabilities in r2rml. From an architectural standpoint, SQL is the
last place I want to put much business logic, and when I do write SQL I
don't want to stray too far from ANSI standard.

Further comment on conditional PredicteObjectMaps below.

On Thu, 2013-03-14 at 01:05 -0500, Juan Sequeda wrote:
> Paul,
> 
> 
> Comments in-line
> 
> 
> On Wed, Mar 13, 2013 at 7:46 PM, Paul Tyson <phtyson@sbcglobal.net>
> wrote:
>         I see this list has no traffic for several months but I
>         thought I would
>         try here first. If anyone knows of a more active forum for
>         discussion,
>         please advise.
>         
>         I've run into a couple of issues implementing an R2RML
>         processor, and I
>         wondered if others have encountered these and if so would you
>         share some
>         thoughts on how to solve them.
>         
>         First, I want to transform a column value in the R2RML
>         processor, rather
>         than in SQL, because it is quite inconvenient to do it in SQL.
>         I would
>         like the R2RML mapping spec to specify the value
>         transformation. My
>         solution was to add a "columnValueConstructor" predicate to
>         the Term
>         Map, with a range of values restricted to id values known to
>         the R2RML
>         processor. The handlers for each column value constructor must
>         be
>         hardcoded into the R2RML processor. While this suits my
>         purpose, it is
>         obviously not completely general or easily extensible. Ideally
>         there
>         might be a standard ValueMap construct that could either be
>         defined by a
>         well-known ID or an actual function specification of some
>         sort. A
>         reference to a ValueMap inside a term map would tell the
>         processor to
>         transform the column value before emitting it as RDF.
> 
> 
> If I understand correctly, you are trying to do something like this
> [1]. Currently, the only way to do value transformation is by pushing
> it down into SQL using SQL CASE. 
> 
> 
> Can you tell us why it is inconvenient to do it in SQL?
> 
> 
> Having a way to express the translation in R2RML was widely discussed.
> Please see [2,3, 4]. Actually, this was ISSUE-72 (R2RML Lookup tables)
> [5], and as you can see, this was postponed. 
> 
> 
> [1] http://www.w3.org/TR/r2rml/#example-translationtable
> 
> [2] http://lists.w3.org/Archives/Public/public-rdb2rdf-wg/2011Dec/0068.html
> 
> [3] http://www.w3.org/2001/sw/rdb2rdf/wiki/Translating_Database_Values_to_RDF_Terms
> [4] http://lists.w3.org/Archives/Public/public-rdb2rdf-wg/2011Dec/0020.html
> [5] http://www.w3.org/2001/sw/rdb2rdf/track/issues/72
>  
>         
>         Second, I want to conditionally emit a predicate and object
>         for a
>         subject, depending on the column value returned from the
>         object map. I
>         can imagine a workaround by defining appropriate SQL views in
>         the
>         mapping spec, but in some cases it would seem more efficient
>         and
>         transparent to place a guard condition on a
>         PredicateObjectMap.
> 
> 
> It seems that this could be done with SQL CASE. However, if Lookup
> Tables were part of R2RML, then it would be possible with that too.
> 
> 

On further analysis, my particular use case for conditional
PredicateObjectMaps disappeared. But I still can imagine a use for this
feature. If r2rml had an expression language, it might look something
like:

@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix xrr: <http://example.org/r2rml-extension#>.
@prefix xfn: <http://www.w3.org/2005/xpath-functions/#>.
[a rr:PredicateObjectMap;
 xrr:onCondition [a xrr:Test; 
                  xrr:argument [xrr:varname _:arg1;
                                xrr:value [rr:column "FOO"]];
                  xrr:expression (
                   (xfn:not (xfn:numeric-equal 
                             0 
                             (xfn:compare _:arg1 ""))))];
 rr:predicateMap "...";
 rr:objectMap "..."].

The r2rml processor would only emit the predicate and object terms if
the value in column "FOO" was a non-empty string.

> 
> 
> Conclusion: looks like we have another request for R2RML Lookup
> tables. 

I would request the more general capability of arbitrary transformation
of column values in r2rml.

Regards,
--Paul

> 
> 
> What do others think?
>  
>         
>         I would appreciate any comments on these issues.
>         
>         Regards,
>         --Paul
>         
>         
> 
> 

Received on Friday, 15 March 2013 03:14:06 UTC