+ don't assert NOT NULL for vars with disjoints in the binding
authorEric Prud'hommeaux <eric@w3.org>
Sat, 09 Jan 2010 10:59:13 -0500
changeset 137 aafd5a43289d
parent 136 5aa8c9c0a6e2
child 138 9f82ffaafe02
+ don't assert NOT NULL for vars with disjoints in the binding
src/main/scala/RDB2RDFMain.scala
src/test/scala/RDB2RDFTest.scala
--- a/src/main/scala/RDB2RDFMain.scala	Sat Jan 09 10:37:57 2010 -0500
+++ b/src/main/scala/RDB2RDFMain.scala	Sat Jan 09 10:59:13 2010 -0500
@@ -337,10 +337,11 @@
 	/* Examine each triple, updating the compilation state. */
 	val state2 = triplepatterns.foldLeft(state)((incState,s) => bindOnPredicate(db, incState, s, enforceForeignKeys))
 	val nullExprs = findVars(gp).foldLeft(Set[sql.Expression]())((s, vvar) => {
-	  state2.varmap(vvar) match {
-	    case RDFBNoder(relation, relalias, disjoints) => s
-	    case _ => s ++ Set(sql.RelationalExpressionNotNull(sql.PrimaryExpressionAttr(varToAttribute(state2.varmap, vvar))))
-	  }})
+	  if (varToAttributeDisjoints(state2.varmap, vvar).size == 0)
+	    s ++ Set(sql.RelationalExpressionNotNull(sql.PrimaryExpressionAttr(varToAttribute(state2.varmap, vvar))))
+	  else
+	    s
+	})
 	R2RState(state2.joins, state2.varmap, state2.exprs ++ nullExprs)
       }
       case sparql.TableConjunction(list) => {
--- a/src/test/scala/RDB2RDFTest.scala	Sat Jan 09 10:37:57 2010 -0500
+++ b/src/test/scala/RDB2RDFTest.scala	Sat Jan 09 10:59:13 2010 -0500
@@ -575,7 +575,6 @@
    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 R_who.lastName="Smith"
-   AND (G_union0.bday IS NOT NULL) AND (G_union0.who IS NOT NULL)
 """).get // !!!    AND (G_union0.bday IS NOT NULL) AND (G_union0.who IS NOT NULL)
     val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
     assert(generated === parsed)
@@ -632,7 +631,8 @@
  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"
+   AND R_who.birthday IS NOT NULL AND R_who.empid IS NOT NULL
+   AND R_who.lastName="Smith"
 """).get
     val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
     assert(generated === parsed)
@@ -690,7 +690,6 @@
    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 R_who.empid IS NOT NULL AND R_who.lastName="Smith"
-   AND (G_union1.bday IS NOT NULL)
 """).get
     val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
     assert(generated === parsed)
@@ -752,7 +751,7 @@
                   ) AS G_opt1 ON 1=1
        INNER JOIN Employee AS R_emp
  WHERE (G_opt1._DISJOINT_ IS NULL OR R_emp.empid=G_opt1.emp)
-   AND R_emp.lastName IS NOT NULL AND G_opt1.emp IS NOT NULL
+   AND R_emp.lastName IS NOT NULL
 """).get
     val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
     assert(generated === parsed)
@@ -833,10 +832,10 @@
        INNER JOIN Employee AS R_emp4
  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 G_opt1.birthday IS NOT NULL AND R_emp1.empid IS NOT NULL AND R_emp1.lastName<R_emp2.lastName
+   AND R_emp1.lastName<R_emp2.lastName
    AND R_emp2.empid IS NOT NULL AND R_emp2.lastName<R_emp3.lastName
    AND R_emp3.empid IS NOT NULL AND R_emp3.lastName<R_emp4.lastName
-   AND R_emp4.empid IS NOT NULL
+   AND R_emp4.empid IS NOT NULL AND R_emp1.empid IS NOT NULL
 """).get
     val generated = RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), false, false)
     assert(generated === parsed)