--- a/src/main/scala/SparqlToSql.scala Wed May 19 21:02:04 2010 +0200
+++ b/src/main/scala/SparqlToSql.scala Wed May 19 21:57:02 2010 +0200
@@ -720,40 +720,41 @@
/** Create the select for the nested graph pattern.
*/
- val optionalState = mapGraphPattern(db, emptyState, gp, enforceForeignKeys)
- val optionalVars = gp.findVars
- val disjointNo = sql.NamedAttribute(sql.PrimaryExpressionTyped(sql.Datatype.INTEGER,sql.Name("" + initState.joins.size)),
+ val nestedState = mapGraphPattern(db, emptyState, gp, enforceForeignKeys)
+ val nestedVars = gp.findVars
+ /** */
+ val joinNo = sql.NamedAttribute(sql.PrimaryExpressionTyped(sql.Datatype.INTEGER,sql.Name("" + initState.joins.size)),
sql.AttrAlias(sql.Name("_DISJOINT_")))
val leftJoinVars = gp.findVars.toList
- val attrlist:Set[sql.NamedAttribute] = leftJoinVars.foldLeft(Set(disjointNo))((attrs, v) =>
- attrs ++ Set(sql.NamedAttribute(varToAttribute(optionalState.varmap, sparql.VarAssignable(v)), sql.AttrAlias(attrAliasNameFromVar(sparql.VarAssignable(v)))))
+ val attrlist:Set[sql.NamedAttribute] = leftJoinVars.foldLeft(Set(joinNo))((attrs, v) =>
+ attrs ++ Set(sql.NamedAttribute(varToAttribute(nestedState.varmap, sparql.VarAssignable(v)), sql.AttrAlias(attrAliasNameFromVar(sparql.VarAssignable(v)))))
)
val subselect = sql.Select(
sql.AttributeList(attrlist),
- sql.TableList(optionalState.joins),
- optionalState.exprs.size match {
+ sql.TableList(nestedState.joins),
+ nestedState.exprs.size match {
case 0 => None
- case 1 => Some(optionalState.exprs.toList(0))
- case _ => Some(sql.ExprConjunction(optionalState.exprs))
+ case 1 => Some(nestedState.exprs.toList(0))
+ case _ => Some(sql.ExprConjunction(nestedState.exprs))
}
)
/** Create a condition to test if this OPTIONAL was matched (called
* _DISJOINT_ as OPTIONAL behaves pretty much like a disjunction).
*/
- val optionalCond = sql.RelationalExpressionNull(sql.PrimaryExpressionAttr(
+ val nestedCond = sql.RelationalExpressionNull(sql.PrimaryExpressionAttr(
sql.RelVarAttr(leftJoinAlias, sql.Attribute(sql.Name("_DISJOINT_")))))
/** Bind variables to the attributes projected from the subselect; handle
* corefs (equivalence with earlier bindings).
*/
val outerState2 =
- optionalVars.foldLeft(
+ nestedVars.foldLeft(
R2RState(initState.joins,
initState.varmap,
Set[sql.Expression]()))((myState, v) =>
- subselectVars(myState, sparql.VarAssignable(v), leftJoinAlias, optionalCond,
- initState.varmap, optionalState.varmap, true))
+ subselectVars(myState, sparql.VarAssignable(v), leftJoinAlias, nestedCond,
+ initState.varmap, nestedState.varmap, true))
/** The final state includes the subselect as a join, the variables bound
* to subselect projection, and no new expresssions. The expressions