~ overhauled test schema -- in synch with http://www.w3.org/2008/07/MappingRules/SampleTables.sql
authorEric Prud'hommeaux <eric@w3.org>
Thu, 07 Jan 2010 19:25:14 -0500
changeset 125 d7a285ec49f6
parent 124 8017d349fa32
child 126 03503fe0284f
~ overhauled test schema -- in synch with http://www.w3.org/2008/07/MappingRules/SampleTables.sql
src/test/scala/RDB2RDFTest.scala
--- a/src/test/scala/RDB2RDFTest.scala	Thu Jan 07 19:20:54 2010 -0500
+++ b/src/test/scala/RDB2RDFTest.scala	Thu Jan 07 19:25:14 2010 -0500
@@ -22,16 +22,20 @@
 
   val db2:DatabaseDesc = DatabaseDesc(
     Map(Relation("Employee") -> 
-	RelationDesc(Option(Attribute("id")), 
-		     Map(Attribute("id") -> Value(Datatype.INTEGER),
+	RelationDesc(Option(Attribute("empid")), 
+		     Map(Attribute("empid") -> Value(Datatype.INTEGER),
 			 Attribute("lastName") -> Value(Datatype.STRING),
 			 Attribute("birthday") -> Value(Datatype.DATE),
-			 Attribute("manager") -> Value(Datatype.INTEGER),
-			 Attribute("address") -> Value(Datatype.INTEGER))),
-	Relation("Manage") -> 
+			 Attribute("manager") -> Value(Datatype.INTEGER))),
+	Relation("Tasks") -> 
+	RelationDesc(Option(Attribute("taskid")),
+		     Map(Attribute("taskid") -> Value(Datatype.INTEGER),
+			 Attribute("name") -> Value(Datatype.STRING),
+			 Attribute("lead") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
+	Relation("TaskAssignments") -> 
 	RelationDesc(Option(Attribute("id")),
-		     Map(Attribute("manager") -> ForeignKey(Relation("Employee"), Attribute("id")), 
-			 Attribute("manages") -> ForeignKey(Relation("Employee"),  Attribute("id"))))
+		     Map(Attribute("task") -> ForeignKey(Relation("Tasks"), Attribute("taskid")), 
+			 Attribute("employee") -> ForeignKey(Relation("Employee"),  Attribute("empid"))))
       ))
 
 
@@ -146,8 +150,8 @@
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
 SELECT R_emp1.id AS A_emp1, R_emp2.id AS A_emp2, R_emp1.lastName AS A_sharedName
        FROM Employee AS R_emp1
-            INNER JOIN Employee AS R_emp2
- WHERE R_emp1.lastName=R_emp2.lastName AND R_emp1.id IS NOT NULL AND R_emp1.lastName IS NOT NULL AND R_emp2.id IS NOT NULL
+            INNER JOIN Employee AS R_emp2 ON R_emp2.lastName=R_emp1.lastName
+ WHERE R_emp1.id IS NOT NULL AND R_emp1.lastName IS NOT NULL AND R_emp2.id IS NOT NULL
 """).get
     assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), true, false) === sqlSelect)
     true
@@ -242,15 +246,18 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX empP : <http://hr.example/DB/Employee#>
-PREFIX manP : <http://hr.example/DB/Manage#>
+PREFIX task : <http://hr.example/DB/Tasks#>
+PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
 SELECT ?empName ?grandManagName {
          ?emp          empP:lastName   ?empName .
          ?emp          empP:birthday   ?empBday .
-         ?lower        manP:manages   ?emp .
-         ?lower        manP:manager   ?manager .
-         ?manager      empP:birthday   ?manBday .
-         ?upper        manP:manages   ?manager .
-         ?upper        manP:manager   ?grandManager .
+         ?lower        tsks:employee  ?emp .
+         ?lower        tsks:task      ?ltask .
+         ?ltask        task:lead      ?taskLead .
+         ?taskLead     empP:birthday   ?manBday .
+         ?upper        tsks:employee  ?taskLead .
+         ?upper        tsks:task      ?utask .
+         ?utask        task:lead      ?grandManager .
          ?grandManager empP:birthday   ?grandManBday .
          ?grandManager empP:lastName   ?grandManagName
          FILTER (?manBday < ?empBday && ?grandManBday < ?manBday)
@@ -258,21 +265,22 @@
 """).get
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, R_grandManager.lastName AS A_grandManagName
+SELECT R_emp.lastName AS A_empName,
+       R_grandManager.lastName AS A_grandManagName
   FROM Employee AS R_emp
-       INNER JOIN Manage AS R_lower
-       INNER JOIN Employee AS R_manager
-       INNER JOIN Manage AS R_upper
-       INNER JOIN Employee AS R_grandManager
- WHERE R_emp.id=R_lower.manages AND R_manager.id=R_lower.manager AND R_manager.id=R_upper.manages AND R_grandManager.id=R_upper.manager AND R_manager.birthday < R_emp.birthday AND R_grandManager.birthday < R_manager.birthday AND R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
- AND R_emp.id IS NOT NULL
- AND R_lower.id IS NOT NULL
- AND R_manager.id IS NOT NULL
- AND R_upper.id IS NOT NULL
- AND R_grandManager.id IS NOT NULL
- AND R_emp.birthday IS NOT NULL
- AND R_manager.birthday IS NOT NULL
- AND R_grandManager.birthday IS NOT NULL
+       INNER JOIN TaskAssignments AS R_lower ON R_lower.employee=R_emp.empid
+       INNER JOIN Tasks AS R_ltask ON R_ltask.taskid=R_lower.task
+       INNER JOIN Employee AS R_taskLead ON R_taskLead.empid=R_ltask.lead
+       INNER JOIN TaskAssignments AS R_upper ON R_taskLead.empid=R_upper.employee
+       INNER JOIN Tasks AS R_utask ON R_utask.taskid=R_upper.task
+       INNER JOIN Employee AS R_grandManager ON R_grandManager.empid=R_utask.lead
+ WHERE R_taskLead.birthday<R_emp.birthday AND R_grandManager.birthday<R_taskLead.birthday
+   AND R_grandManager.birthday IS NOT NULL AND R_emp.empid IS NOT NULL
+   AND R_taskLead.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
+   AND R_emp.birthday IS NOT NULL AND R_grandManager.empid IS NOT NULL
+   AND R_grandManager.lastName IS NOT NULL AND R_utask.taskid IS NOT NULL
+   AND R_taskLead.birthday IS NOT NULL AND R_ltask.taskid IS NOT NULL
+   AND R_lower.id IS NOT NULL AND R_upper.id IS NOT NULL
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), true, false) === sqlSelect)
   }
@@ -281,15 +289,18 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX empP : <http://hr.example/DB/Employee#>
-PREFIX manP : <http://hr.example/DB/Manage#>
+PREFIX task : <http://hr.example/DB/Tasks#>
+PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
 SELECT ?name
  WHERE { ?who empP:lastName "Smith"^^xsd:string
-         { ?above   manP:manages ?who .
-           ?above   manP:manager ?manager .
-           ?manager empP:lastName  ?name }
+         { ?above   tsks:employee  ?who .
+           ?above   tsks:task      ?atask .
+           ?atask   task:lead      ?taskLead .
+           ?taskLead empP:lastName ?name }
          UNION
-         { ?below   manP:manager ?who .
-           ?below   manP:manages ?managed .
+         { ?below   tsks:task      ?btask .
+           ?btask   task:lead      ?who .
+           ?below   tsks:employee  ?managed .
            ?managed empP:lastName  ?name } }
 """).get
     val sqlParser = Sql()
@@ -297,23 +308,33 @@
 SELECT R_union1.A_name AS A_name
   FROM Employee AS R_who
        INNER JOIN (
-         SELECT 0 AS _DISJOINT_, R_manager.lastName AS A_name, R_above.manager AS A_manager, 
-                R_above.id AS A_above, NULL AS A_below, R_above.manages AS A_who, NULL AS A_managed
-                FROM Manage AS R_above
-                INNER JOIN Employee AS R_manager
-          WHERE R_above.manager=R_manager.id AND R_manager.lastName IS NOT NULL
-                AND R_above.manager IS NOT NULL AND R_above.id IS NOT NULL AND R_above.manages IS NOT NULL
+         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
+           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_atask.lead IS NOT NULL AND R_above.employee IS NOT NULL
+            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_, R_managed.lastName AS A_name, NULL AS A_manager, 
-                NULL AS A_above, R_below.id AS A_below, R_below.manager AS A_who, R_below.manages AS A_managed
-                FROM Manage AS R_below
-                INNER JOIN Employee AS R_managed
-          WHERE R_below.manages=R_managed.id AND R_managed.lastName IS NOT NULL
-                AND R_below.manager IS NOT NULL AND R_below.id IS NOT NULL AND R_below.manages IS NOT NULL
-       ) AS R_union1
- WHERE R_who.lastName="Smith" AND R_who.id IS NOT NULL AND
-       (R_union1._DISJOINT_!=0 OR R_who.id=R_union1.A_who) AND
-       (R_union1._DISJOINT_!=1 OR R_who.id=R_union1.A_who)
+         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
+           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_managed.lastName IS NOT NULL
+            AND R_below.task IS NOT NULL AND R_btask.lead IS NOT NULL
+            AND R_below.id IS NOT NULL
+                       ) AS R_union1
+ WHERE R_who.lastName="Smith"
+       AND R_who.empid IS NOT NULL
+       AND (R_union1._DISJOINT_!=0 OR R_union1.A_who=R_who.empid)
+       AND (R_union1._DISJOINT_!=1 OR R_union1.A_who=R_who.empid)
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -322,15 +343,18 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX empP : <http://hr.example/DB/Employee#>
-PREFIX manP : <http://hr.example/DB/Manage#>
+PREFIX task : <http://hr.example/DB/Tasks#>
+PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
 PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
 SELECT ?name
- WHERE { { ?above   manP:manages ?who .
-           ?above   manP:manager ?manager .
-           ?manager empP:lastName  ?name }
+ WHERE { { ?above   tsks:employee  ?who .
+           ?above   tsks:task      ?atask .
+           ?atask   task:lead      ?taskLead .
+           ?taskLead empP:lastName  ?name }
          UNION
-         { ?below   manP:manager ?who .
-           ?below   manP:manages ?managed .
+         { ?below   tsks:task     ?btask .
+           ?btask   task:lead     ?who .
+           ?below   tsks:employee ?managed .
            ?managed empP:lastName  ?name .
            ?managed empP:birthday  ?bday } 
          ?who empP:lastName "Smith"^^xsd:string .
@@ -339,27 +363,30 @@
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
 SELECT R_union0.A_name AS A_name
-  FROM ( SELECT 0 AS _DISJOINT_, R_above.manager AS A_manager, R_manager.lastName AS A_name, R_above.id AS A_above, 
-                NULL AS A_below, NULL AS A_bday, R_above.manages AS A_who, NULL AS A_managed
-                FROM Manage AS R_above
-                INNER JOIN Employee AS R_manager
-          WHERE R_above.manager IS NOT NULL AND R_above.manager=R_manager.id AND R_above.id IS NOT NULL
-                AND R_above.manages IS NOT NULL AND R_manager.lastName IS NOT NULL
+  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_
+           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 1 AS _DISJOINT_, NULL AS A_manager, R_managed.lastName AS A_name, NULL AS A_above, 
-                R_below.id AS A_below, R_managed.birthday AS A_bday, R_below.manager AS A_who, R_below.manages AS A_managed
-                FROM Manage AS R_below
-                INNER JOIN Employee AS R_managed
-          WHERE R_managed.birthday IS NOT NULL AND R_below.manager IS NOT NULL AND R_below.id IS NOT NULL
-                AND R_below.manages=R_managed.id AND R_below.manages IS NOT NULL AND R_managed.lastName IS NOT NULL
-       ) AS R_union0
+         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_
+           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 R_union0
        INNER JOIN Employee AS R_who
- WHERE R_who.lastName="Smith" AND
-       (R_union0._DISJOINT_!=0 OR R_union0.A_who=R_who.id) AND
-       (R_union0._DISJOINT_!=1 OR R_union0.A_who=R_who.id) AND
-       (R_union0._DISJOINT_!=1 OR R_union0.A_bday=R_who.birthday) AND
-       R_union0.A_who IS NOT NULL AND
-       R_union0.A_bday IS NOT NULL
+ WHERE (R_union0._DISJOINT_!=0 OR R_who.empid=R_union0.A_who)
+   AND (R_union0._DISJOINT_!=1 OR R_who.birthday=R_union0.A_bday)
+   AND (R_union0._DISJOINT_!=1 OR R_who.empid=R_union0.A_who)
+   AND R_union0.A_bday IS NOT NULL AND R_union0.A_who IS NOT NULL AND R_who.lastName="Smith"
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -368,18 +395,21 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX empP : <http://hr.example/DB/Employee#>
-PREFIX manP : <http://hr.example/DB/Manage#>
+PREFIX task : <http://hr.example/DB/Tasks#>
+PREFIX tsks : <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   manP:manages ?who .
-           ?above   manP:manager ?manager .
-           ?manager empP:lastName  ?name }
+         { ?above   tsks:employee ?who .
+           ?above   tsks:task     ?atask .
+           ?atask   task:lead     ?taskLead .
+           ?taskLead empP:lastName  ?name }
          UNION
-         { ?below   manP:manager ?who .
-           ?below   manP:manages ?managed .
+         { ?below   tsks:task     ?btask .
+           ?btask   task:lead     ?who .
+           ?below   tsks:employee ?managed .
            ?managed empP:lastName  ?name .
            ?managed empP:birthday  ?bday } 
        }
@@ -388,26 +418,29 @@
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
 SELECT R_union1.A_name AS A_name
   FROM Employee AS R_who
-       INNER JOIN ( SELECT 0 AS _DISJOINT_, R_above.manager AS A_manager, R_manager.lastName AS A_name, R_above.id AS A_above, 
-                NULL AS A_below, NULL AS A_bday, R_above.manages AS A_who, NULL AS A_managed
-                FROM Manage AS R_above
-                INNER JOIN Employee AS R_manager
-          WHERE R_above.manager IS NOT NULL AND R_above.manager=R_manager.id AND R_above.id IS NOT NULL
-                AND R_above.manages IS NOT NULL AND R_manager.lastName IS NOT NULL
+       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_
+           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 1 AS _DISJOINT_, NULL AS A_manager, R_managed.lastName AS A_name, NULL AS A_above, 
-                R_below.id AS A_below, R_managed.birthday AS A_bday, R_below.manager AS A_who, R_below.manages AS A_managed
-                FROM Manage AS R_below
-                INNER JOIN Employee AS R_managed
-          WHERE R_managed.birthday IS NOT NULL AND R_below.manager IS NOT NULL AND R_below.id IS NOT NULL
-                AND R_below.manages=R_managed.id AND R_below.manages IS NOT NULL AND R_managed.lastName IS NOT NULL
-       ) AS R_union1
- WHERE R_who.lastName="Smith" AND
-       (R_union1._DISJOINT_!=0 OR R_who.id=R_union1.A_who) AND
-       (R_union1._DISJOINT_!=1 OR R_who.id=R_union1.A_who) AND
-       (R_union1._DISJOINT_!=1 OR R_who.birthday=R_union1.A_bday) AND
-       R_who.id IS NOT NULL AND
-       R_who.birthday IS NOT NULL
+         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_
+           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 R_union1
+ WHERE (R_union1._DISJOINT_!=0 OR R_union1.A_who=R_who.empid)
+   AND (R_union1._DISJOINT_!=1 OR R_union1.A_bday=R_who.birthday)
+   AND (R_union1._DISJOINT_!=1 OR R_union1.A_who=R_who.empid)
+   AND R_who.birthday IS NOT NULL AND R_who.empid IS NOT NULL AND R_who.lastName="Smith"
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -416,19 +449,22 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX empP : <http://hr.example/DB/Employee#>
-PREFIX manP : <http://hr.example/DB/Manage#>
+PREFIX task : <http://hr.example/DB/Tasks#>
+PREFIX tsks : <http://hr.example/DB/TaskAssignments#>
 PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
 SELECT ?name
  WHERE {
          ?who empP:lastName "Smith"^^xsd:string
-         { ?above   manP:manages ?who .
-           ?above   manP:manager ?manager .
-           ?manager empP:lastName  ?name }
+         { ?above   tsks:employee  ?who .
+           ?above   tsks:task      ?atask .
+           ?atask   task:lead      ?taskLead .
+           ?taskLead empP:lastName ?name }
          UNION
-         { ?below   manP:manager ?who .
-           ?below   manP:manages ?managed .
-           ?managed empP:lastName  ?name .
-           ?managed empP:birthday  ?bday } 
+         { ?below   tsks:task     ?btask .
+           ?btask   task:lead     ?who .
+           ?below   tsks:employee ?managed .
+           ?managed empP:lastName ?name .
+           ?managed empP:birthday ?bday } 
          ?who empP:birthday ?bday
        }
 """).get
@@ -436,26 +472,29 @@
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
 SELECT R_union1.A_name AS A_name
   FROM Employee AS R_who
-       INNER JOIN ( SELECT 0 AS _DISJOINT_, R_above.manager AS A_manager, R_manager.lastName AS A_name, R_above.id AS A_above, 
-                NULL AS A_below, NULL AS A_bday, R_above.manages AS A_who, NULL AS A_managed
-                FROM Manage AS R_above
-                INNER JOIN Employee AS R_manager
-          WHERE R_above.manager IS NOT NULL AND R_above.manager=R_manager.id AND R_above.id IS NOT NULL
-                AND R_above.manages IS NOT NULL AND R_manager.lastName IS NOT NULL
+       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_
+           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 1 AS _DISJOINT_, NULL AS A_manager, R_managed.lastName AS A_name, NULL AS A_above, 
-                R_below.id AS A_below, R_managed.birthday AS A_bday, R_below.manager AS A_who, R_below.manages AS A_managed
-                FROM Manage AS R_below
-                INNER JOIN Employee AS R_managed
-          WHERE R_managed.birthday IS NOT NULL AND R_below.manager IS NOT NULL AND R_below.id IS NOT NULL
-                AND R_below.manages=R_managed.id AND R_below.manages IS NOT NULL AND R_managed.lastName IS NOT NULL
-       ) AS R_union1
- WHERE R_who.lastName="Smith" AND
-       (R_union1._DISJOINT_!=0 OR R_who.id=R_union1.A_who) AND
-       (R_union1._DISJOINT_!=1 OR R_who.id=R_union1.A_who) AND
-       (R_union1._DISJOINT_!=1 OR R_union1.A_bday=R_who.birthday) AND
-       R_who.id IS NOT NULL AND
-       R_union1.A_bday IS NOT NULL
+         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_
+           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 R_union1
+ WHERE (R_union1._DISJOINT_!=0 OR R_union1.A_who=R_who.empid)
+   AND (R_union1._DISJOINT_!=1 OR R_union1.A_who=R_who.empid)
+   AND (R_union1._DISJOINT_!=1 OR R_who.birthday=R_union1.A_bday)
+   AND R_union1.A_bday IS NOT NULL AND R_who.empid IS NOT NULL AND R_who.lastName="Smith"
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -464,42 +503,27 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX emplP: <http://hr.example/DB/Employee#>
-PREFIX mangP: <http://hr.example/DB/Manage#>
 
 SELECT ?empName ?managName ?grandManagName
- WHERE {          ?emp            emplP:lastName   ?empName
-         OPTIONAL { ?mang         mangP:manages    ?emp .
-                    ?mang         mangP:manager    ?manager .
-                    ?manager      emplP:lastName   ?managName .
-                    ?grandMang    mangP:manages    ?manager .
-                    ?grandMang    mangP:manager    ?grandManager .
-                    ?grandManager emplP:lastName   ?grandManagName } }
+ WHERE {      ?emp          emplP:lastName   ?empName
+   OPTIONAL { ?emp          emplP:manager    ?manager .
+              ?manager      emplP:lastName   ?managName .
+              ?manager      emplP:manager    ?grandManager .
+              ?grandManager emplP:lastName   ?grandManagName } }
 """).get
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, R_opt1.A_managName AS A_managName, R_opt1.A_grandManagName AS A_grandManagName
-       FROM Employee AS R_emp
-            LEFT OUTER JOIN (
-    SELECT 1 AS _DISJOINT_, R_grandManager.lastName AS A_grandManagName, R_manager.lastName AS A_managName, R_mang.manages AS A_emp,
-       R_grandMang.manager AS A_grandManager,
-       R_mang.id AS A_mang,
-       R_mang.manager AS A_manager,
-       R_grandMang.id AS A_grandMang
-           FROM Manage AS R_mang
-                INNER JOIN Employee AS R_manager
-                INNER JOIN Manage AS R_grandMang
-                INNER JOIN Employee AS R_grandManager
-     WHERE R_mang.manager=R_manager.id AND R_mang.manager=R_grandMang.manages AND R_grandMang.manager=R_grandManager.id
-       AND (R_grandMang.manager IS NOT NULL)
-       AND (R_mang.manages IS NOT NULL)
-       AND (R_mang.id IS NOT NULL)
-       AND (R_grandManager.lastName IS NOT NULL)
-       AND (R_mang.manager IS NOT NULL)
-       AND (R_manager.lastName IS NOT NULL)
-       AND (R_grandMang.id IS NOT NULL)
-             ) AS R_opt1 ON R_emp.id=R_opt1.A_emp
- WHERE R_emp.lastName IS NOT NULL
-   AND R_emp.id IS NOT NULL
+SELECT R_emp.lastName AS A_empName, R_opt1.A_grandManagName AS A_grandManagName, R_opt1.A_managName AS A_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_
+         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 R_opt1 ON R_opt1.A_emp=R_emp.empid
+ WHERE R_emp.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -510,36 +534,26 @@
 PREFIX emplP: <http://hr.example/DB/Employee#>
 
 SELECT ?empName ?grandManagName
- WHERE { OPTIONAL { ?manager      emplP:manager    ?emp .
-                    ?manager      emplP:manager    ?grandManager .
+ WHERE { OPTIONAL { ?taskLead     emplP:manager    ?emp .
+                    ?taskLead     emplP:manager    ?grandManager .
                     ?grandManager emplP:lastName   ?grandManagName } 
                   ?emp            emplP:lastName   ?empName }
 """).get
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName,
-       R_opt1.A_grandManagName AS A_grandManagName
-  FROM (
-SELECT 1 AS _EMPTY_
-
-                       ) AS _EMPTY_
+SELECT R_emp.lastName AS A_empName, R_opt1.A_grandManagName AS A_grandManagName
+  FROM ( SELECT 1 AS _EMPTY_ ) AS _EMPTY_
        LEFT OUTER JOIN (
-SELECT R_grandManager.lastName AS A_grandManagName,
-       R_manager.id AS A_manager,
-       R_manager.manager AS A_grandManager,
-       R_manager.manager AS A_emp,
-       1 AS _DISJOINT_
-  FROM Employee AS R_manager
-       INNER JOIN Employee AS R_grandManager
- WHERE (R_manager.manager=R_grandManager.id)
-       AND (R_manager.id IS NOT NULL)
-       AND (R_manager.manager IS NOT NULL)
-       AND (R_grandManager.lastName IS NOT NULL)
-                       ) AS R_opt1 ON 1=1
+       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_
+         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 R_opt1 ON 1=1
        INNER JOIN Employee AS R_emp
- WHERE ((R_opt1._DISJOINT_ IS NULL) OR (R_opt1.A_emp=R_emp.id))
-       AND (R_opt1.A_emp IS NOT NULL)
-       AND (R_emp.lastName IS NOT NULL)""").get
+ WHERE (R_opt1._DISJOINT_ IS NULL OR R_emp.empid=R_opt1.A_emp)
+   AND R_emp.lastName IS NOT NULL
+   AND R_opt1.A_emp IS NOT NULL
+""").get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
 
@@ -547,39 +561,34 @@
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX emplP: <http://hr.example/DB/Employee#>
-PREFIX mangP: <http://hr.example/DB/Manage#>
 
 SELECT ?empName ?managName ?grandManagName
  WHERE {          ?emp            emplP:lastName   ?empName
-       OPTIONAL { ?mang           mangP:manages    ?emp .
-                  ?mang           mangP:manager    ?manager .
+       OPTIONAL { ?emp            emplP:manager    ?manager .
                   ?manager        emplP:lastName   ?managName
-         OPTIONAL { ?grandMang    mangP:manages    ?manager .
-                    ?grandMang    mangP:manager    ?grandManager .
+         OPTIONAL { ?manager      emplP:manager    ?grandManager .
                     ?grandManager emplP:lastName   ?grandManagName } }
        }
 """).get
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.lastName AS A_empName, R_opt1.A_managName AS A_managName, R_opt1.A_grandManagName AS A_grandManagName
-       FROM Employee AS R_emp
-            LEFT OUTER JOIN (
-    SELECT 1 AS _DISJOINT_, R_opt2.A_grandManagName AS A_grandManagName, R_manager.lastName AS A_managName, R_mang.manages AS A_emp,
-           R_mang.manager AS A_manager, R_mang.id AS A_mang, R_opt2.A_grandMang AS A_grandMang, R_opt2.A_grandManager AS A_grandManager
-           FROM Manage AS R_mang
-                INNER JOIN Employee AS R_manager
-                LEFT OUTER JOIN (
-        SELECT 2 AS _DISJOINT_, R_grandManager.lastName AS A_grandManagName, R_grandMang.manages AS A_manager,
-               R_grandMang.id AS A_grandMang, R_grandMang.manager AS A_grandManager
-               FROM Manage AS R_grandMang
-                    INNER JOIN Employee AS R_grandManager
-         WHERE R_grandMang.manager=R_grandManager.id AND R_grandMang.manages IS NOT NULL AND R_grandMang.manager IS NOT NULL
-           AND R_grandManager.lastName IS NOT NULL AND R_grandMang.id IS NOT NULL
-                 ) AS R_opt2 ON R_mang.manager=R_opt2.A_manager
-          WHERE R_mang.manager=R_manager.id
-            AND R_mang.manages IS NOT NULL AND R_mang.id IS NOT NULL AND R_mang.manager IS NOT NULL AND R_manager.lastName IS NOT NULL
-             ) AS R_opt1 ON R_emp.id=R_opt1.A_emp
- WHERE R_emp.lastName IS NOT NULL AND R_emp.id IS NOT NULL
+SELECT R_emp.lastName AS A_empName, R_opt1.A_grandManagName AS A_grandManagName, R_opt1.A_managName AS A_managName
+  FROM Employee AS R_emp
+       LEFT OUTER JOIN (
+       SELECT R_emp.empid AS A_emp, R_opt2.A_grandManagName AS A_grandManagName, R_opt2.A_grandManager AS A_grandManager, R_manager.lastName AS A_managName, R_emp.manager AS A_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_
+                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 R_opt2 ON R_opt2.A_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 R_opt1 ON R_opt1.A_emp=R_emp.empid
+ WHERE R_emp.empid IS NOT NULL AND R_emp.lastName IS NOT NULL
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }
@@ -605,36 +614,24 @@
 SELECT R_emp1.lastName AS A_emp1Name, R_emp2.lastName AS A_emp2Name, R_emp3.lastName AS A_emp3Name
   FROM Employee AS R_emp1
        LEFT OUTER JOIN (
-			SELECT 1 AS _DISJOINT_,
-			       R_emp1.id AS A_emp1,
-			       R_emp1.birthday AS A_birthday
-			  FROM Employee AS R_emp1
-			 WHERE R_emp1.id IS NOT NULL
-			       AND R_emp1.birthday IS NOT NULL
-			) AS R_opt1 ON R_emp1.id=R_opt1.A_emp1
-       INNER JOIN Employee AS R_emp2 ON R_emp1.lastName<R_emp2.lastName
-				    AND R_emp2.id IS NOT NULL
-				    AND R_emp2.lastName IS NOT NULL
+       SELECT R_emp1.birthday AS A_birthday, R_emp1.empid AS A_emp1, 1 AS _DISJOINT_
+         FROM Employee AS R_emp1
+        WHERE R_emp1.birthday IS NOT NULL AND R_emp1.empid IS NOT NULL
+                  ) AS R_opt1 ON R_opt1.A_emp1=R_emp1.empid
+       INNER JOIN Employee AS R_emp2
        LEFT OUTER JOIN (
-			SELECT 3 AS _DISJOINT_,
-			       R_emp2.id AS A_emp2,
-			       R_emp2.birthday AS A_birthday
-			  FROM Employee AS R_emp2
-			 WHERE R_emp2.id IS NOT NULL
-			   AND R_emp2.birthday IS NOT NULL
-			) AS R_opt3 ON R_emp2.id=R_opt3.A_emp2
-				   AND (R_opt1._DISJOINT_ IS NULL OR R_opt1.A_birthday=R_opt3.A_birthday)
-       INNER JOIN Employee AS R_emp3 ON (R_opt1._DISJOINT_ IS NULL OR R_opt1.A_birthday=R_emp3.birthday)
-				    AND R_emp2.lastName<R_emp3.lastName
-				    AND R_emp3.id IS NOT NULL
-				    AND R_emp3.lastName IS NOT NULL
-       INNER JOIN Employee AS R_emp4 ON R_emp3.lastName<R_emp4.lastName
-				    AND (R_opt1._DISJOINT_ IS NULL OR R_opt1.A_birthday=R_emp4.birthday)
-				    AND R_emp4.id IS NOT NULL
-				    AND R_emp4.lastName IS NOT NULL
- WHERE R_emp1.id IS NOT NULL
-   AND R_emp1.lastName IS NOT NULL
-   AND R_opt1.A_birthday IS NOT NULL
+       SELECT R_emp2.birthday AS A_birthday, R_emp2.empid AS A_emp2, 3 AS _DISJOINT_
+         FROM Employee AS R_emp2
+        WHERE R_emp2.birthday IS NOT NULL AND R_emp2.empid IS NOT NULL
+                  ) AS R_opt3 ON (R_opt1._DISJOINT_ IS NULL OR R_opt3.A_birthday=R_opt1.A_birthday) AND R_opt3.A_emp2=R_emp2.empid
+       INNER JOIN Employee AS R_emp3
+       INNER JOIN Employee AS R_emp4
+ WHERE (R_opt1._DISJOINT_ IS NULL OR R_emp3.birthday=R_opt1.A_birthday)
+   AND (R_opt1._DISJOINT_ IS NULL OR R_emp4.birthday=R_opt1.A_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 R_opt1.A_birthday IS NOT NULL
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), false, false) === sqlSelect)
   }