~ simplified subselectVars prototype
authorEric Prud'hommeaux <eric@w3.org>
Fri, 29 Jan 2010 16:09:58 -0500
changeset 143 f1283558478f
parent 142 c6714b599c35
child 144 43bbad68f4fb
~ simplified subselectVars prototype
src/main/scala/RDB2RDFMain.scala
--- a/src/main/scala/RDB2RDFMain.scala	Fri Jan 29 15:46:41 2010 -0500
+++ b/src/main/scala/RDB2RDFMain.scala	Fri Jan 29 16:09:58 2010 -0500
@@ -383,8 +383,10 @@
    * <outerState> could be <myState> -- spliting roles could make proofs easier?
    */
   def subselectVars(myState:R2RState, v:sparql.Var, optionalAlias:sql.RelAlias,
-		    optionalCond:sql.RelationalExpression, outerState:R2RState,
-		    optionalState:R2RState, isOpt:Boolean):R2RState = {
+		    optionalCond:sql.RelationalExpression,
+		    outerVarmap:Map[sparql.Var, SQL2RDFValueMapper],
+		    nestedVarmap:Map[sparql.Var, SQL2RDFValueMapper],
+		    isOpt:Boolean):R2RState = {
     val varAliasAttr = sql.RelAliasAttribute(optionalAlias, sql.Attribute(attrAliasNameFromVar(v)))
     if (myState.varmap.contains(v)) {
       /* The variable has already been bound. */
@@ -400,13 +402,13 @@
       } else
 	Map()
       val newConstraints =
-	if (varToAttribute(outerState.varmap, v) != varAliasAttr) {
+	if (varToAttribute(outerVarmap, v) != varAliasAttr) {
 	  /* Constraint against binding from earlier GP. */
 	  val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varAliasAttr),
-						      sql.PrimaryExpressionAttr(varToAttribute(outerState.varmap, v)))
-	  if (varToAttributeDisjoints(outerState.varmap, v).size > 0)
+						      sql.PrimaryExpressionAttr(varToAttribute(outerVarmap, v)))
+	  if (varToAttributeDisjoints(outerVarmap, v).size > 0)
 	    // (union0._DISJOINT_ != 0 OR union0.x=union1.x) AND (union1._DISJOINT_ != 2 OR union0.x=union1.x)
-	    varToAttributeDisjoints(outerState.varmap, v) map ((d) =>
+	    varToAttributeDisjoints(outerVarmap, v) map ((d) =>
 	      sql.ExprDisjunction({
 		if (isOpt) Set(d, constraint)
 		else Set(sql.ExprConjunction(Set(d, optionalCond)), constraint)
@@ -422,7 +424,7 @@
     } else {
       /* This variable is new to the outer context. */
       val p = PartialBinding(Set(BindingConstraint(optionalCond, varAliasAttr)))
-      val mapper:SQL2RDFValueMapper = optionalState.varmap(v) match {
+      val mapper:SQL2RDFValueMapper = nestedVarmap(v) match {
 	case IntMapper(_)      => IntMapper(p)
 	case StringMapper(_)   => StringMapper(p)
 	case DateMapper(_)   => DateMapper(p)
@@ -515,7 +517,7 @@
 	  val disjointCond = sql.RelationalExpressionNe(sql.PrimaryExpressionAttr(sql.RelAliasAttribute(unionAlias, sql.Attribute(sql.Name("_DISJOINT_")))),
 							sql.PrimaryExpressionTyped(sql.Datatype.INTEGER,sql.Name("" + no)))
 	  val outerState2 = disjointVars.foldLeft(outerState)((myState, v) =>
-	      subselectVars(myState, v, unionAlias, disjointCond, outerState, disjointState, false))
+	      subselectVars(myState, v, unionAlias, disjointCond, outerState.varmap, disjointState.varmap, false))
 	  (outerState2, no+1)
 	})
 	val subselect = sql.Subselect(sql.Union(subselects))
@@ -583,7 +585,7 @@
 		     state_postLeadingTable.varmap,
 		     Set[sql.Expression]()))((myState, v) => 
 		       subselectVars(myState, v, leftJoinAlias, optionalCond,
-				     state_postLeadingTable, optionalState, true))
+				     state_postLeadingTable.varmap, optionalState.varmap, true))
 
 	/* The final state includes the subselect as a join, the variables bound
 	 * to subselect projection, and no new expresssions. The expressions