--- a/src/test/scala/RDB2RDFTest.scala Thu Jan 07 23:38:58 2010 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Fri Jan 08 00:45:30 2010 -0500
@@ -1,12 +1,44 @@
+/* RDB2RDFTest: transform SPARQL to SQL and compare against a reference query.
+ *
+ * These work with a database:
+ *
+Employee+----------+------------+---------+
+| empid | lastName | birthday | manager |
++-------+----------+------------+---------+
+| 18 | Johnson | 1969-11-08 | NULL |
+| 253 | Smith | 1979-01-18 | 18 |
+| 255 | Jones | 1981-03-24 | 253 |
+| 19 | Xu | 1966-11-08 | NULL |
+| 254 | Ishita | 1971-10-31 | 253 |
++-------+----------+------------+---------+
+
+Tasks----+--------+------+
+| taskid | name | lead |
++--------+--------+------+
+| 1 | widget | 18 |
+| 2 | dingus | 253 |
+| 3 | thingy | 18 |
+| 4 | toy | 253 |
++--------+--------+------+
+
+TaskAssignments--------+
+| id | task | employee |
++----+------+----------+
+| 1 | 253 | 18 |
+| 2 | 255 | 253 |
+| 3 | 255 | 19 |
+| 4 | 254 | 253 |
++----+------+----------+
+
+ */
+
package w3c.sw
import org.scalatest.FunSuite
import java.net.URI
import w3c.sw.sql.{Sql,DatabaseDesc,Relation,RelationDesc,Attribute,Value,Datatype,ForeignKey,Name}
import w3c.sw.sparql.Sparql
-import w3c.sw.rdb2rdf.{RDB2RDF,StemURI,
- PrimaryKey // nuke
- }
+import w3c.sw.rdb2rdf.{RDB2RDF,StemURI}
class RDB2RDFTest extends FunSuite {
@@ -39,15 +71,26 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.empid AS A_emp
+SELECT R_emp.empid AS emp
FROM Employee AS R_emp
INNER JOIN Employee AS R_empid18
WHERE R_empid18.empid=R_emp.manager AND R_empid18.empid=18 AND R_emp.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
+ val output = """
++-----+
+| emp |
++-----+
+| 253 |
++-----+
+"""
}
+ /* Data can be converted to turtle strings, or left as native formats for
+ * mapping the the querier. Here are a couple turtle string generators:
+ */
+
test("SELECT <x> { ?sf <p> <x>} (in-SQL Nodizer)") {
val sparqlParser = Sparql()
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
@@ -57,16 +100,21 @@
}
""").get
val sqlParser = Sql()
- val StemUrlString = "\"http://hr.example/DB/\""
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT CONCAT(""" + StemUrlString + """, "Employee", "/", "empid", ".", R_emp.empid, "#record") AS A_emp
+SELECT CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_emp.empid, "#record") AS emp
FROM Employee AS R_emp
INNER JOIN Employee AS R_empid18
WHERE R_empid18.empid=R_emp.manager AND R_empid18.empid=18 AND R_emp.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, true)
assert(generated === parsed)
- true
+ val output = """
++------------------------------------------------+
+| emp |
++------------------------------------------------+
+| http://hr.example/DB/Employee/empid.253#record |
++------------------------------------------------+
+"""
}
test("SELECT <x> { ?sf <p> \"asdf\"} (in-SQL Nodizer)") {
@@ -78,15 +126,24 @@
}
""").get
val sqlParser = Sql()
- val StemUrlString = "\"http://hr.example/DB/\""
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT CONCAT("\"", R_emp.lastName, "\"^^<http://www.w3.org/2001/XMLSchema#string>") AS A_name
+SELECT CONCAT("'", R_emp.lastName, "'^^<http://www.w3.org/2001/XMLSchema#string>") AS name
FROM Employee AS R_emp
WHERE R_emp.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, true)
assert(generated === parsed)
- true
+ val output = """
++----------------------------------------------------+
+| name |
++----------------------------------------------------+
+| Johnson^^<http://www.w3.org/2001/XMLSchema#string> |
+| Smith^^<http://www.w3.org/2001/XMLSchema#string> |
+| Jones^^<http://www.w3.org/2001/XMLSchema#string> |
+| Xu^^<http://www.w3.org/2001/XMLSchema#string> |
+| Ishita^^<http://www.w3.org/2001/XMLSchema#string> |
++----------------------------------------------------+
+"""
}
test("<s> <p> ?x") {
@@ -94,19 +151,25 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
SELECT ?manager {
-<http://hr.example/DB/Employee/empid.18#record> empP:manager ?manager
+<http://hr.example/DB/Employee/empid.253#record> empP:manager ?manager
}
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_manager.empid AS A_manager
- FROM Employee AS R_empid18
+SELECT R_manager.empid AS manager
+ FROM Employee AS R_empid253
INNER JOIN Employee AS R_manager
- WHERE R_manager.empid=R_empid18.manager AND R_empid18.empid=18 AND R_manager.empid IS NOT NULL
+ WHERE R_manager.empid=R_empid253.manager AND R_empid253.empid=253 AND R_manager.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
- true
+ val output = """
++---------+
+| manager |
++---------+
+| 18 |
++---------+
+"""
}
test("?s <p> 18") {
@@ -122,35 +185,53 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.empid AS A_emp
+SELECT R_emp.empid AS emp
FROM Employee AS R_emp
INNER JOIN Employee AS R_18
WHERE R_18.empid=R_emp.manager AND R_18.empid=18 AND R_emp.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
- true
+ val output = """
++-----+
+| emp |
++-----+
+| 253 |
++-----+
+"""
}
test("?s1 <p> ?x . ?s2 <p> ?x") {
val sparqlParser = Sparql()
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
-PREFIX empP : <http://hr.example/DB/Employee#>
-SELECT ?emp1 ?emp2 ?sharedName {
- ?emp1 empP:lastName ?sharedName .
- ?emp2 empP:lastName ?sharedName
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
+SELECT ?task1 ?task2 {
+ ?task1 tass:employee ?who .
+ ?task2 tass:employee ?who
+ FILTER(?task1 < ?task2)
}
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp1.empid AS A_emp1, R_emp2.empid AS A_emp2, R_emp1.lastName AS A_sharedName
- FROM Employee AS R_emp1
- INNER JOIN Employee AS R_emp2 ON R_emp2.lastName=R_emp1.lastName
- WHERE R_emp1.empid IS NOT NULL AND R_emp1.lastName IS NOT NULL AND R_emp2.empid IS NOT NULL
+SELECT R_task1.id AS task1, R_task2.id AS task2
+ FROM TaskAssignments AS R_task1
+ INNER JOIN Employee AS R_who ON R_who.empid=R_task1.employee
+ INNER JOIN TaskAssignments AS R_task2 ON R_who.empid=R_task2.employee
+ WHERE R_task1.id<R_task2.id
+ AND R_task1.id IS NOT NULL AND R_task2.id IS NOT NULL AND R_who.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
- true
+ val output = """
++-------+-------+
+| task1 | task2 |
++-------+-------+
+| 2 | 4 |
+| 2 | 5 |
+| 4 | 5 |
+| 6 | 7 |
++-------+-------+
+"""
}
test("transform SQLbgp") {
@@ -165,7 +246,7 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_manageName
+SELECT R_emp.lastName AS empName, R_manager.lastName AS manageName
FROM Employee AS R_emp
INNER JOIN Employee AS R_manager ON R_manager.empid=R_emp.manager
WHERE R_emp .lastName IS NOT NULL AND R_emp .empid IS NOT NULL
@@ -173,6 +254,15 @@
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
+ val output = """
++---------+------------+
+| empName | manageName |
++---------+------------+
+| Smith | Johnson |
+| Jones | Smith |
+| Ishita | Smith |
++---------+------------+
+"""
}
test("transform tup1 no-enforce") {
@@ -186,13 +276,20 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName
+SELECT R_emp.lastName AS empName
FROM Employee AS R_emp
WHERE R_emp.manager=18 AND R_emp.lastName IS NOT NULL
AND R_emp.empid IS NOT NULL
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
assert(generated === parsed)
+ val output = """
++---------+
+| empName |
++---------+
+| Smith |
++---------+
+"""
}
test("transform tup1 enforce") {
@@ -206,7 +303,7 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName
+SELECT R_emp.lastName AS empName
FROM Employee AS R_emp
INNER JOIN Employee AS R_empid18
WHERE R_empid18.empid=R_emp.manager AND R_empid18.empid=18 AND R_emp.lastName IS NOT NULL
@@ -214,6 +311,13 @@
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
+ val output = """
++---------+
+| empName |
++---------+
+| Smith |
++---------+
+"""
}
@@ -230,7 +334,7 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName
+SELECT R_emp.lastName AS empName
FROM Employee AS R_emp
INNER JOIN Employee AS R_manager
WHERE R_manager.empid=R_emp.manager AND R_manager.lastName="Johnson" AND R_emp.lastName IS NOT NULL
@@ -239,6 +343,13 @@
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
+ val output = """
++---------+
+| empName |
++---------+
+| Smith |
++---------+
+"""
}
test("transform filter1") {
@@ -246,16 +357,16 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
PREFIX task : <http://hr.example/DB/Tasks#>
-PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
SELECT ?empName ?grandManagName {
?emp empP:lastName ?empName .
?emp empP:birthday ?empBday .
- ?lower tsks:employee ?emp .
- ?lower tsks:task ?ltask .
+ ?lower tass:employee ?emp .
+ ?lower tass:task ?ltask .
?ltask task:lead ?taskLead .
?taskLead empP:birthday ?manBday .
- ?upper tsks:employee ?taskLead .
- ?upper tsks:task ?utask .
+ ?upper tass:employee ?taskLead .
+ ?upper tass:task ?utask .
?utask task:lead ?grandManager .
?grandManager empP:birthday ?grandManBday .
?grandManager empP:lastName ?grandManagName
@@ -264,8 +375,8 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName,
- R_grandManager.lastName AS A_grandManagName
+SELECT R_emp.lastName AS empName,
+ R_grandManager.lastName AS grandManagName
FROM Employee AS R_emp
INNER JOIN TaskAssignments AS R_lower ON R_emp.empid=R_lower.employee
INNER JOIN Tasks AS R_ltask ON R_ltask.taskid=R_lower.task
@@ -283,6 +394,12 @@
""").get
val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false)
assert(generated === parsed)
+ val output = """
++---------+----------------+
+| empName | grandManagName |
++---------+----------------+
+| Jones | Johnson |
++---------+----------------+"""
}
test("transform disj1") {
@@ -290,28 +407,28 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
PREFIX task : <http://hr.example/DB/Tasks#>
-PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
SELECT ?name
WHERE { ?who empP:lastName "Smith"^^xsd:string
- { ?above tsks:employee ?who .
- ?above tsks:task ?atask .
+ { ?above tass:employee ?who .
+ ?above tass:task ?atask .
?atask task:lead ?taskLead .
?taskLead empP:lastName ?name }
UNION
- { ?below tsks:task ?btask .
+ { ?below tass:task ?btask .
?btask task:lead ?who .
- ?below tsks:employee ?managed .
+ ?below tass:employee ?managed .
?managed empP:lastName ?name } }
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT G_union1.A_name AS A_name
+SELECT G_union1.name AS name
FROM Employee AS R_who
INNER JOIN (
- SELECT 0 AS _DISJOINT_, R_above.id AS A_above, R_above.task AS A_atask,
- R_above.employee AS A_who, R_taskLead.lastName AS A_name,
- R_atask.lead AS A_taskLead,
- NULL AS A_below, NULL AS A_btask, NULL AS A_managed
+ SELECT 0 AS _DISJOINT_, R_above.id AS above, R_above.task AS atask,
+ R_above.employee AS who, R_taskLead.lastName AS name,
+ R_atask.lead AS taskLead,
+ NULL AS below, NULL AS btask, NULL AS managed
FROM TaskAssignments AS R_above
INNER JOIN Tasks AS R_atask ON R_atask.taskid=R_above.task
INNER JOIN Employee AS R_taskLead ON R_taskLead.empid=R_atask.lead
@@ -319,11 +436,11 @@
AND R_above.task IS NOT NULL AND R_taskLead.lastName IS NOT NULL
AND R_above.id IS NOT NULL
UNION
- SELECT 1 AS _DISJOINT_, NULL AS A_above, NULL AS A_atask,
- R_btask.lead AS A_who,R_managed.lastName AS A_name,
- NULL AS A_taskLead,
- R_below.id AS A_below, R_below.task AS A_btask,
- R_below.employee AS A_managed
+ SELECT 1 AS _DISJOINT_, NULL AS above, NULL AS atask,
+ R_btask.lead AS who,R_managed.lastName AS name,
+ NULL AS taskLead,
+ R_below.id AS below, R_below.task AS btask,
+ R_below.employee AS managed
FROM TaskAssignments AS R_below
INNER JOIN Tasks AS R_btask ON R_btask.taskid=R_below.task
INNER JOIN Employee AS R_managed ON R_managed.empid=R_below.employee
@@ -333,11 +450,13 @@
) AS G_union1
WHERE R_who.lastName="Smith"
AND R_who.empid IS NOT NULL
- AND (G_union1._DISJOINT_!=0 OR G_union1.A_who=R_who.empid)
- AND (G_union1._DISJOINT_!=1 OR G_union1.A_who=R_who.empid)
+ AND (G_union1._DISJOINT_!=0 OR G_union1.who=R_who.empid)
+ AND (G_union1._DISJOINT_!=1 OR G_union1.who=R_who.empid)
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform assymDisj1") {
@@ -345,17 +464,17 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
PREFIX task : <http://hr.example/DB/Tasks#>
-PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
- WHERE { { ?above tsks:employee ?who .
- ?above tsks:task ?atask .
+ WHERE { { ?above tass:employee ?who .
+ ?above tass:task ?atask .
?atask task:lead ?taskLead .
?taskLead empP:lastName ?name }
UNION
- { ?below tsks:task ?btask .
+ { ?below tass:task ?btask .
?btask task:lead ?who .
- ?below tsks:employee ?managed .
+ ?below tass:employee ?managed .
?managed empP:lastName ?name .
?managed empP:birthday ?bday }
?who empP:lastName "Smith"^^xsd:string .
@@ -363,20 +482,20 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT G_union0.A_name AS A_name
+SELECT G_union0.name AS name
FROM (
- SELECT R_above.id AS A_above, R_above.task AS A_atask, NULL AS A_bday, NULL AS A_below,
- NULL AS A_btask, NULL AS A_managed, R_taskLead.lastName AS A_name,
- R_atask.lead AS A_taskLead, R_above.employee AS A_who, 0 AS _DISJOINT_
+ SELECT R_above.id AS above, R_above.task AS atask, NULL AS bday, NULL AS below,
+ NULL AS btask, NULL AS managed, R_taskLead.lastName AS name,
+ R_atask.lead AS taskLead, R_above.employee AS who, 0 AS _DISJOINT_
FROM TaskAssignments AS R_above
INNER JOIN Tasks AS R_atask ON R_atask.taskid=R_above.task
INNER JOIN Employee AS R_taskLead ON R_taskLead.empid=R_atask.lead
WHERE R_above.employee IS NOT NULL AND R_above.id IS NOT NULL AND R_above.task IS NOT NULL
AND R_atask.lead IS NOT NULL AND R_taskLead.lastName IS NOT NULL
UNION
- SELECT NULL AS A_above, NULL AS A_atask, R_managed.birthday AS A_bday, R_below.id AS A_below,
- R_below.task AS A_btask, R_below.employee AS A_managed, R_managed.lastName AS A_name,
- NULL AS A_taskLead, R_btask.lead AS A_who, 1 AS _DISJOINT_
+ SELECT NULL AS above, NULL AS atask, R_managed.birthday AS bday, R_below.id AS below,
+ R_below.task AS btask, R_below.employee AS managed, R_managed.lastName AS name,
+ NULL AS taskLead, R_btask.lead AS who, 1 AS _DISJOINT_
FROM TaskAssignments AS R_below
INNER JOIN Tasks AS R_btask ON R_btask.taskid=R_below.task
INNER JOIN Employee AS R_managed ON R_managed.empid=R_below.employee
@@ -384,13 +503,15 @@
AND R_btask.lead IS NOT NULL AND R_managed.birthday IS NOT NULL AND R_managed.lastName IS NOT NULL
) AS G_union0
INNER JOIN Employee AS R_who
- WHERE (G_union0._DISJOINT_!=0 OR R_who.empid=G_union0.A_who)
- AND (G_union0._DISJOINT_!=1 OR R_who.birthday=G_union0.A_bday)
- AND (G_union0._DISJOINT_!=1 OR R_who.empid=G_union0.A_who)
- AND G_union0.A_bday IS NOT NULL AND G_union0.A_who IS NOT NULL AND R_who.lastName="Smith"
+ WHERE (G_union0._DISJOINT_!=0 OR R_who.empid=G_union0.who)
+ AND (G_union0._DISJOINT_!=1 OR R_who.birthday=G_union0.bday)
+ AND (G_union0._DISJOINT_!=1 OR R_who.empid=G_union0.who)
+ AND G_union0.bday IS NOT NULL AND G_union0.who IS NOT NULL AND R_who.lastName="Smith"
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform assymDisj1 reversed") {
@@ -398,54 +519,56 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
PREFIX task : <http://hr.example/DB/Tasks#>
-PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?who empP:lastName "Smith"^^xsd:string .
?who empP:birthday ?bday
- { ?above tsks:employee ?who .
- ?above tsks:task ?atask .
+ { ?above tass:employee ?who .
+ ?above tass:task ?atask .
?atask task:lead ?taskLead .
?taskLead empP:lastName ?name }
UNION
- { ?below tsks:task ?btask .
+ { ?below tass:task ?btask .
?btask task:lead ?who .
- ?below tsks:employee ?managed .
+ ?below tass:employee ?managed .
?managed empP:lastName ?name .
?managed empP:birthday ?bday }
}
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT G_union1.A_name AS A_name
+SELECT G_union1.name AS name
FROM Employee AS R_who
INNER JOIN (
- SELECT R_above.id AS A_above, R_above.task AS A_atask, NULL AS A_bday, NULL AS A_below,
- NULL AS A_btask, NULL AS A_managed, R_taskLead.lastName AS A_name,
- R_atask.lead AS A_taskLead, R_above.employee AS A_who, 0 AS _DISJOINT_
+ SELECT R_above.id AS above, R_above.task AS atask, NULL AS bday, NULL AS below,
+ NULL AS btask, NULL AS managed, R_taskLead.lastName AS name,
+ R_atask.lead AS taskLead, R_above.employee AS who, 0 AS _DISJOINT_
FROM TaskAssignments AS R_above
INNER JOIN Tasks AS R_atask ON R_atask.taskid=R_above.task
INNER JOIN Employee AS R_taskLead ON R_taskLead.empid=R_atask.lead
WHERE R_above.employee IS NOT NULL AND R_above.id IS NOT NULL AND R_above.task IS NOT NULL
AND R_atask.lead IS NOT NULL AND R_taskLead.lastName IS NOT NULL
UNION
- SELECT NULL AS A_above, NULL AS A_atask, R_managed.birthday AS A_bday, R_below.id AS A_below,
- R_below.task AS A_btask, R_below.employee AS A_managed, R_managed.lastName AS A_name,
- NULL AS A_taskLead, R_btask.lead AS A_who, 1 AS _DISJOINT_
+ SELECT NULL AS above, NULL AS atask, R_managed.birthday AS bday, R_below.id AS below,
+ R_below.task AS btask, R_below.employee AS managed, R_managed.lastName AS name,
+ NULL AS taskLead, R_btask.lead AS who, 1 AS _DISJOINT_
FROM TaskAssignments AS R_below
INNER JOIN Tasks AS R_btask ON R_btask.taskid=R_below.task
INNER JOIN Employee AS R_managed ON R_managed.empid=R_below.employee
WHERE R_below.employee IS NOT NULL AND R_below.id IS NOT NULL AND R_below.task IS NOT NULL
AND R_btask.lead IS NOT NULL AND R_managed.birthday IS NOT NULL AND R_managed.lastName IS NOT NULL
) AS G_union1
- WHERE (G_union1._DISJOINT_!=0 OR G_union1.A_who=R_who.empid)
- AND (G_union1._DISJOINT_!=1 OR G_union1.A_bday=R_who.birthday)
- AND (G_union1._DISJOINT_!=1 OR G_union1.A_who=R_who.empid)
+ WHERE (G_union1._DISJOINT_!=0 OR G_union1.who=R_who.empid)
+ AND (G_union1._DISJOINT_!=1 OR G_union1.bday=R_who.birthday)
+ AND (G_union1._DISJOINT_!=1 OR G_union1.who=R_who.empid)
AND R_who.birthday IS NOT NULL AND R_who.empid IS NOT NULL AND R_who.lastName="Smith"
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform assymDisj1 interspersed") {
@@ -453,19 +576,19 @@
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
PREFIX empP : <http://hr.example/DB/Employee#>
PREFIX task : <http://hr.example/DB/Tasks#>
-PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
+PREFIX tass : <http://hr.example/DB/TaskAssignments#>
PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?who empP:lastName "Smith"^^xsd:string
- { ?above tsks:employee ?who .
- ?above tsks:task ?atask .
+ { ?above tass:employee ?who .
+ ?above tass:task ?atask .
?atask task:lead ?taskLead .
?taskLead empP:lastName ?name }
UNION
- { ?below tsks:task ?btask .
+ { ?below tass:task ?btask .
?btask task:lead ?who .
- ?below tsks:employee ?managed .
+ ?below tass:employee ?managed .
?managed empP:lastName ?name .
?managed empP:birthday ?bday }
?who empP:birthday ?bday
@@ -473,34 +596,36 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT G_union1.A_name AS A_name
+SELECT G_union1.name AS name
FROM Employee AS R_who
INNER JOIN (
- SELECT R_above.id AS A_above, R_above.task AS A_atask, NULL AS A_bday, NULL AS A_below,
- NULL AS A_btask, NULL AS A_managed, R_taskLead.lastName AS A_name,
- R_atask.lead AS A_taskLead, R_above.employee AS A_who, 0 AS _DISJOINT_
+ SELECT R_above.id AS above, R_above.task AS atask, NULL AS bday, NULL AS below,
+ NULL AS btask, NULL AS managed, R_taskLead.lastName AS name,
+ R_atask.lead AS taskLead, R_above.employee AS who, 0 AS _DISJOINT_
FROM TaskAssignments AS R_above
INNER JOIN Tasks AS R_atask ON R_atask.taskid=R_above.task
INNER JOIN Employee AS R_taskLead ON R_taskLead.empid=R_atask.lead
WHERE R_above.employee IS NOT NULL AND R_above.id IS NOT NULL AND R_above.task IS NOT NULL
AND R_atask.lead IS NOT NULL AND R_taskLead.lastName IS NOT NULL
UNION
- SELECT NULL AS A_above, NULL AS A_atask, R_managed.birthday AS A_bday, R_below.id AS A_below,
- R_below.task AS A_btask, R_below.employee AS A_managed, R_managed.lastName AS A_name,
- NULL AS A_taskLead, R_btask.lead AS A_who, 1 AS _DISJOINT_
+ SELECT NULL AS above, NULL AS atask, R_managed.birthday AS bday, R_below.id AS below,
+ R_below.task AS btask, R_below.employee AS managed, R_managed.lastName AS name,
+ NULL AS taskLead, R_btask.lead AS who, 1 AS _DISJOINT_
FROM TaskAssignments AS R_below
INNER JOIN Tasks AS R_btask ON R_btask.taskid=R_below.task
INNER JOIN Employee AS R_managed ON R_managed.empid=R_below.employee
WHERE R_below.employee IS NOT NULL AND R_below.id IS NOT NULL AND R_below.task IS NOT NULL
AND R_btask.lead IS NOT NULL AND R_managed.birthday IS NOT NULL AND R_managed.lastName IS NOT NULL
) AS G_union1
- WHERE (G_union1._DISJOINT_!=0 OR G_union1.A_who=R_who.empid)
- AND (G_union1._DISJOINT_!=1 OR G_union1.A_who=R_who.empid)
- AND (G_union1._DISJOINT_!=1 OR R_who.birthday=G_union1.A_bday)
- AND G_union1.A_bday IS NOT NULL AND R_who.empid IS NOT NULL AND R_who.lastName="Smith"
+ WHERE (G_union1._DISJOINT_!=0 OR G_union1.who=R_who.empid)
+ AND (G_union1._DISJOINT_!=1 OR G_union1.who=R_who.empid)
+ AND (G_union1._DISJOINT_!=1 OR R_who.birthday=G_union1.bday)
+ AND G_union1.bday IS NOT NULL AND R_who.empid IS NOT NULL AND R_who.lastName="Smith"
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform optJoin1") {
@@ -517,20 +642,22 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, G_opt1.A_grandManagName AS A_grandManagName, G_opt1.A_managName AS A_managName
+SELECT R_emp.lastName AS empName, G_opt1.grandManagName AS grandManagName, G_opt1.managName AS managName
FROM Employee AS R_emp
LEFT OUTER JOIN (
- SELECT R_emp.empid AS A_emp, R_grandManager.lastName AS A_grandManagName, R_manager.manager AS A_grandManager, R_manager.lastName AS A_managName, R_emp.manager AS A_manager, 1 AS _DISJOINT_
+ SELECT R_emp.empid AS emp, R_grandManager.lastName AS grandManagName, R_manager.manager AS grandManager, R_manager.lastName AS managName, R_emp.manager AS manager, 1 AS _DISJOINT_
FROM Employee AS R_emp
INNER JOIN Employee AS R_manager ON R_manager.empid=R_emp.manager
INNER JOIN Employee AS R_grandManager ON R_grandManager.empid=R_manager.manager
WHERE R_emp.empid IS NOT NULL AND R_emp.manager IS NOT NULL AND R_grandManager.lastName IS NOT NULL
AND R_manager.lastName IS NOT NULL AND R_manager.manager IS NOT NULL
- ) AS G_opt1 ON G_opt1.A_emp=R_emp.empid
+ ) AS G_opt1 ON G_opt1.emp=R_emp.empid
WHERE R_emp.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform leadOpt1") {
@@ -546,21 +673,23 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, G_opt1.A_grandManagName AS A_grandManagName
+SELECT R_emp.lastName AS empName, G_opt1.grandManagName AS grandManagName
FROM ( SELECT 1 AS _EMPTY_ ) AS _EMPTY_
LEFT OUTER JOIN (
- SELECT R_taskLead.manager AS A_emp, R_grandManager.lastName AS A_grandManagName, R_taskLead.manager AS A_grandManager, R_taskLead.empid AS A_taskLead, 1 AS _DISJOINT_
+ SELECT R_taskLead.manager AS emp, R_grandManager.lastName AS grandManagName, R_taskLead.manager AS grandManager, R_taskLead.empid AS taskLead, 1 AS _DISJOINT_
FROM Employee AS R_taskLead
INNER JOIN Employee AS R_grandManager ON R_grandManager.empid=R_taskLead.manager
WHERE R_grandManager.lastName IS NOT NULL AND R_taskLead.empid IS NOT NULL AND R_taskLead.manager IS NOT NULL
) AS G_opt1 ON 1=1
INNER JOIN Employee AS R_emp
- WHERE (G_opt1._DISJOINT_ IS NULL OR R_emp.empid=G_opt1.A_emp)
+ WHERE (G_opt1._DISJOINT_ IS NULL OR R_emp.empid=G_opt1.emp)
AND R_emp.lastName IS NOT NULL
- AND G_opt1.A_emp IS NOT NULL
+ AND G_opt1.emp IS NOT NULL
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform nestOpt") {
@@ -578,26 +707,28 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, G_opt1.A_grandManagName AS A_grandManagName, G_opt1.A_managName AS A_managName
+SELECT R_emp.lastName AS empName, G_opt1.grandManagName AS grandManagName, G_opt1.managName AS managName
FROM Employee AS R_emp
LEFT OUTER JOIN (
- SELECT R_emp.empid AS A_emp, G_opt2.A_grandManagName AS A_grandManagName, G_opt2.A_grandManager AS A_grandManager, R_manager.lastName AS A_managName, R_emp.manager AS A_manager, 1 AS _DISJOINT_
+ SELECT R_emp.empid AS emp, G_opt2.grandManagName AS grandManagName, G_opt2.grandManager AS grandManager, R_manager.lastName AS managName, R_emp.manager AS manager, 1 AS _DISJOINT_
FROM Employee AS R_emp
INNER JOIN Employee AS R_manager ON R_manager.empid=R_emp.manager
LEFT OUTER JOIN (
- SELECT R_grandManager.lastName AS A_grandManagName, R_manager.manager AS A_grandManager, R_manager.empid AS A_manager, 2 AS _DISJOINT_
+ SELECT R_grandManager.lastName AS grandManagName, R_manager.manager AS grandManager, R_manager.empid AS manager, 2 AS _DISJOINT_
FROM Employee AS R_manager
INNER JOIN Employee AS R_grandManager ON R_grandManager.empid=R_manager.manager
WHERE R_grandManager.lastName IS NOT NULL AND R_manager.empid IS NOT NULL AND R_manager.manager IS NOT NULL
- ) AS G_opt2 ON G_opt2.A_manager=R_emp.manager
+ ) AS G_opt2 ON G_opt2.manager=R_emp.manager
WHERE R_emp.empid IS NOT NULL
AND R_emp.manager IS NOT NULL
AND R_manager.lastName IS NOT NULL
- ) AS G_opt1 ON G_opt1.A_emp=R_emp.empid
+ ) AS G_opt1 ON G_opt1.emp=R_emp.empid
WHERE R_emp.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}
test("transform equivOpt1") {
@@ -618,30 +749,32 @@
""").get
val sqlParser = Sql()
val parsed = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp1.lastName AS A_emp1Name, R_emp2.lastName AS A_emp2Name, R_emp3.lastName AS A_emp3Name
+SELECT R_emp1.lastName AS emp1Name, R_emp2.lastName AS emp2Name, R_emp3.lastName AS emp3Name
FROM Employee AS R_emp1
LEFT OUTER JOIN (
- SELECT R_emp1.birthday AS A_birthday, R_emp1.empid AS A_emp1, 1 AS _DISJOINT_
+ SELECT R_emp1.birthday AS birthday, R_emp1.empid AS emp1, 1 AS _DISJOINT_
FROM Employee AS R_emp1
WHERE R_emp1.birthday IS NOT NULL AND R_emp1.empid IS NOT NULL
- ) AS G_opt1 ON G_opt1.A_emp1=R_emp1.empid
+ ) AS G_opt1 ON G_opt1.emp1=R_emp1.empid
INNER JOIN Employee AS R_emp2
LEFT OUTER JOIN (
- SELECT R_emp2.birthday AS A_birthday, R_emp2.empid AS A_emp2, 3 AS _DISJOINT_
+ SELECT R_emp2.birthday AS birthday, R_emp2.empid AS emp2, 3 AS _DISJOINT_
FROM Employee AS R_emp2
WHERE R_emp2.birthday IS NOT NULL AND R_emp2.empid IS NOT NULL
- ) AS G_opt3 ON (G_opt1._DISJOINT_ IS NULL OR G_opt3.A_birthday=G_opt1.A_birthday) AND G_opt3.A_emp2=R_emp2.empid
+ ) AS G_opt3 ON (G_opt1._DISJOINT_ IS NULL OR G_opt3.birthday=G_opt1.birthday) AND G_opt3.emp2=R_emp2.empid
INNER JOIN Employee AS R_emp3
INNER JOIN Employee AS R_emp4
- WHERE (G_opt1._DISJOINT_ IS NULL OR R_emp3.birthday=G_opt1.A_birthday)
- AND (G_opt1._DISJOINT_ IS NULL OR R_emp4.birthday=G_opt1.A_birthday)
+ WHERE (G_opt1._DISJOINT_ IS NULL OR R_emp3.birthday=G_opt1.birthday)
+ AND (G_opt1._DISJOINT_ IS NULL OR R_emp4.birthday=G_opt1.birthday)
AND R_emp1.empid IS NOT NULL AND R_emp1.lastName IS NOT NULL AND R_emp1.lastName<R_emp2.lastName
AND R_emp2.empid IS NOT NULL AND R_emp2.lastName IS NOT NULL AND R_emp2.lastName<R_emp3.lastName
AND R_emp3.empid IS NOT NULL AND R_emp3.lastName IS NOT NULL AND R_emp3.lastName<R_emp4.lastName
- AND R_emp4.empid IS NOT NULL AND R_emp4.lastName IS NOT NULL AND G_opt1.A_birthday IS NOT NULL
+ AND R_emp4.empid IS NOT NULL AND R_emp4.lastName IS NOT NULL AND G_opt1.birthday IS NOT NULL
""").get
- val transformed = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
- assert(transformed === parsed)
+ val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
}