interop between SQL-views and RDF-views

On Sunday, I taugh FeDeRate to generate views (one page of code).
  http://dvcs.w3.org/hg/FeDeRate/file/636ceb7f6d4d/src/main/scala/SparqlToSparqlToSql.scala#l14

An accompanying test demonstrates the efficacy.
  http://dvcs.w3.org/hg/FeDeRate/file/636ceb7f6d4d/src/test/scala/SparqlToSparqlToSqlTest.scala#l69

Given some DDL:
[[
CREATE TABLE Employee (empid INT, PRIMARY KEY (empid), firstName STRING, lastName STRING, birthday DATE, manager INT, FOREIGN KEY (manager) REFERENCES Employee(empid));
CREATE TABLE Tasks (taskid INT, PRIMARY KEY (taskid), name STRING, lead INT, FOREIGN KEY (lead) REFERENCES Employee(empid));
CREATE TABLE TaskAssignments (id INT PRIMARY KEY, PRIMARY KEY (id), task INT, FOREIGN KEY (task) REFERENCES Tasks(taskid), employee INT, FOREIGN KEY (employee) REFERENCES Employee(empid));
]]
and a configuration rule:
[[
PREFIX foaf : <http://xmlns.com/foaf/0.1/>
PREFIX empP : <http://hr.example/DB/Employee#>
CONSTRUCT { ?who a               foaf:Person .
            ?who foaf:first_name ?fname .
            ?who foaf:last_name  ?lname }
    WHERE { ?who empP:firstName  ?fname .
            ?who empP:lastName   ?lname }
]]
it emits an SQL triples view:
[[
CREATE VIEW triples AS
  SELECT "<http://xmlns.com/foaf/0.1/Person>" AS O, "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" AS P, CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_S.empid, "#record") AS S
    FROM Employee AS R_S
   WHERE (R_S.firstName IS NOT NULL)
     AND (R_S.lastName IS NOT NULL)
UNION
  SELECT CONCAT("'", R_S.firstName, "'^^<http://www.w3.org/2001/XMLSchema#string>") AS O, "<http://xmlns.com/foaf/0.1/first_name>" AS P, CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_S.empid, "#record") AS S
    FROM Employee AS R_S
   WHERE (R_S.empid IS NOT NULL)
     AND (R_S.firstName IS NOT NULL)
UNION
  SELECT CONCAT("'", R_S.lastName, "'^^<http://www.w3.org/2001/XMLSchema#string>") AS O, "<http://xmlns.com/foaf/0.1/last_name>" AS P, CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_S.empid, "#record") AS S
    FROM Employee AS R_S
   WHERE (R_S.empid IS NOT NULL)
     AND (R_S.lastName IS NOT NULL)
]]

-- 
-ericP

Received on Tuesday, 2 March 2010 15:24:17 UTC