~ pass transform disj1
authorEric Prud'hommeaux <bertails@w3.org>
Wed, 30 Dec 2009 10:25:01 -0500
changeset 88 77007f8d3764
parent 87 98edfae72eae
child 89 ea90beafa37c
~ pass transform disj1
src/main/scala/RDB2RDFMain.scala
src/test/scala/RDB2RDFTest.scala
--- a/src/main/scala/RDB2RDFMain.scala	Wed Dec 30 09:55:53 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala	Wed Dec 30 10:25:01 2009 -0500
@@ -285,8 +285,8 @@
 	list.foldLeft(state)((incState,s) => mapGraphPattern(db, incState, s, pk, enforeForeignKeys))
       }
       case TableDisjunction(list) => {
-	val unionAlias = RelAlias(Name("R_union1"))
-	var initDisjoints:Set[Select] = Set()
+	val unionAlias = RelAlias(Name("R_union" + state.joins.size))
+	val initDisjoints:Set[Select] = Set()
 	val emptyState = R2RState(
 	  Set[AliasedResource](), 
 	  Map[Var, SQL2RDFValueMapper](), 
@@ -305,11 +305,8 @@
 	    TableList(disjointState.joins),
 	    Expression(disjointState.exprs)
 	  )
-	  println("sel: " + sel)
-	  println("outerState: " + outerState)
 	  val outerState2 = disjointVars.foldLeft(outerState)((myState, v) => {
-	    val unionAliasAttr = RelAliasAttribute(unionAlias, varToAttribute(disjointState.varmap, v).attribute)
-	    println("examining " + v)
+	    val unionAliasAttr = RelAliasAttribute(unionAlias, Attribute(Name("A_" + v.s)))
 	    if (myState.varmap.contains(v)) {
 	      /* The variable has already been bound. */
 	      if (varToAttribute(myState.varmap, v) == unionAliasAttr)
@@ -320,12 +317,11 @@
 		R2RState(myState.joins, myState.varmap, myState.exprs + PrimaryExpressionEq(varToAttribute(myState.varmap, v), RValueAttr(unionAliasAttr)))
 	    } else {
 	      /* This variable is new to the outer context. */
-	      val unionAttr = RelAliasAttribute(unionAlias, Attribute(Name("A_" + v.s)))
 	      val mapper:SQL2RDFValueMapper = disjointState.varmap(v) match {
-		case RDFNoder(rel, constrainMe)  => RDFNoder(rel, unionAttr)
-		case StringMapper(constrainMe)   => StringMapper(unionAttr)
-		case IntMapper(constrainMe)      => IntMapper(unionAttr)
-		case RDFBNoder(rel, constrainMe) => RDFBNoder(rel, unionAttr)
+		case RDFNoder(rel, constrainMe)  => RDFNoder(rel, unionAliasAttr)
+		case StringMapper(constrainMe)   => StringMapper(unionAliasAttr)
+		case IntMapper(constrainMe)      => IntMapper(unionAliasAttr)
+		case RDFBNoder(rel, constrainMe) => RDFBNoder(rel, unionAliasAttr)
 	      }
 	      R2RState(myState.joins, myState.varmap + (v -> mapper), myState.exprs)
 	    }
--- a/src/test/scala/RDB2RDFTest.scala	Wed Dec 30 09:55:53 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala	Wed Dec 30 10:25:01 2009 -0500
@@ -241,16 +241,20 @@
   FROM Employee AS R_who
        INNER JOIN (
          SELECT R_manager.lastName AS A_name, R_above.manages AS A_who
+                , R_above.id AS A_above, R_above.manager AS A_manager
                 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
        UNION
          SELECT R_managed.lastName AS A_name, R_below.manager AS A_who
+                , R_below.id AS A_below, 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_union1.A_who=R_who.id AND R_who.lastName="Smith"
+ WHERE R_who.id=R_union1.A_who AND R_who.lastName="Smith" AND R_who.id IS NOT NULL
 """).get
     assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id"))), false) === sqlSelect)
   }