--- a/src/main/scala/RDB2RDFMain.scala Thu Jan 07 19:18:56 2010 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Thu Jan 07 19:20:54 2010 -0500
@@ -64,15 +64,22 @@
}
def uriConstraint(state:R2RState, constrainMe:sql.RelAliasAttribute, u:sparql.ObjUri, enforeForeignKeys:Boolean):R2RState = {
- // println("equiv+= " + toString(constrainMe) + "=" + value)
- //R2RState(state.joins, state.varmap, state.exprs + RelationalExpressionEq(constrainMe,PrimaryExpressionTyped(SQLDatatype.INTEGER,Name(u.v.s))))
- val relvar = if (enforeForeignKeys) sql.RelAliasAttribute(constrainMe.relalias, sql.Attribute(sql.Name(u.attr.s))) else constrainMe
- R2RState(state.joins, state.varmap, state.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(relvar),sql.PrimaryExpressionTyped(sql.Datatype.INTEGER,sql.Name(u.v.s))))
+ val relvar =
+ if (enforeForeignKeys)
+ sql.RelAliasAttribute(constrainMe.relalias, sql.Attribute(sql.Name(u.attr.s)))
+ else
+ constrainMe
+ R2RState(state.joins,
+ state.varmap,
+ state.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(relvar),
+ sql.PrimaryExpressionTyped(sql.Datatype.INTEGER,sql.Name(u.v.s))))
}
def literalConstraint(state:R2RState, constrainMe:sql.RelAliasAttribute, lit:sparql.Literal, dt:sql.Datatype):R2RState = {
- // println("equiv+= " + toString(attr) + "=" + lit)
- R2RState(state.joins, state.varmap, state.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(constrainMe),sql.PrimaryExpressionTyped(dt,sql.Name(lit.lit.lexicalForm))))
+ R2RState(state.joins,
+ state.varmap,
+ state.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(constrainMe),
+ sql.PrimaryExpressionTyped(dt,sql.Name(lit.lit.lexicalForm))))
}
/** varConstraint
@@ -96,7 +103,8 @@
if (state.varmap.contains(v) && varToAttribute(state.varmap, v) != constrainMe) {
/* The variable has already been bound to another attribute. */
/* Constraint against the initial binding for this variable. */
- val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varToAttribute(state.varmap, v)), sql.PrimaryExpressionAttr(constrainMe))
+ val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(constrainMe),
+ sql.PrimaryExpressionAttr(varToAttribute(state.varmap, v)))
R2RState(state.joins, state.varmap,
if (varToAttributeDisjoints(state.varmap, v).size > 0) {
state.exprs ++ {varToAttributeDisjoints(state.varmap, v) map ((d) => sql.ExprDisjunction(Set(d, constraint)))}
@@ -164,8 +172,16 @@
}
val state_subjJoin = R2RState(state_postSubj.joins + sql.InnerJoin(sql.AliasedResource(rel,relalias)), state_postSubj.varmap, state_postSubj.exprs)
+ try { db.relationdescs(rel).attributes(attr) } catch {
+ case e:java.util.NoSuchElementException =>
+ throw new Exception("error processing { " + s + " " + p + " " + o + " } :db.relationdescs(" + rel + ").attributes(" + attr + ") not found in " + db)
+ }
val (targetattr, targetrel, dt, state_fkeys:R2RState) = db.relationdescs(rel).attributes(attr) match {
case sql.ForeignKey(fkrel, fkattr) => {
+ try { db.relationdescs(fkrel).attributes(fkattr) } catch {
+ case e:java.util.NoSuchElementException =>
+ throw new Exception("db.relationdescs(" + fkrel + ").attributes(" + fkattr + ") not found in " + db)
+ }
val fkdt = db.relationdescs(fkrel).attributes(fkattr) match {
case sql.ForeignKey(dfkrel, dfkattr) => error("foreign key " + rel.n + "." + attr.n +
"->" + fkrel.n + "." + fkattr.n +
@@ -177,7 +193,8 @@
val fkaliasattr = sql.RelAliasAttribute(oRelAlias, fkattr)
val state_t = R2RState(state_subjJoin.joins + sql.InnerJoin(sql.AliasedResource(fkrel,oRelAlias)),
state_subjJoin.varmap,
- state_subjJoin.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(fkaliasattr),sql.PrimaryExpressionAttr(objattr)))
+ state_subjJoin.exprs + sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(fkaliasattr),
+ sql.PrimaryExpressionAttr(objattr)))
(fkaliasattr, fkrel, fkdt, state_t)
} else {
@@ -402,8 +419,8 @@
val newConstraints =
if (varToAttribute(outerState.varmap, v) != varAliasAttr) {
/* Constraint against binding from earlier GP. */
- val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varToAttribute(outerState.varmap, v)),
- sql.PrimaryExpressionAttr(varAliasAttr))
+ val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varAliasAttr),
+ sql.PrimaryExpressionAttr(varToAttribute(outerState.varmap, v)))
if (varToAttributeDisjoints(outerState.varmap, 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) =>
@@ -508,8 +525,8 @@
Map()
val newConstraints = {
/* Constraint against binding from earlier GP. */
- val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varToAttribute(state_postLeadingTable.varmap, v)),
- sql.PrimaryExpressionAttr(varAliasAttr))
+ val constraint = sql.RelationalExpressionEq(sql.PrimaryExpressionAttr(varAliasAttr),
+ sql.PrimaryExpressionAttr(varToAttribute(state_postLeadingTable.varmap, v)))
if (varToAttributeDisjoints(state_postLeadingTable.varmap, v).size > 0)
// (leftJoin0._DISJOINT_ IS NOT NULL AND leftJoin1._DISJOINT_ IS NOT NULL) OR leftJoin0.x=leftJoin1.x
varToAttributeDisjoints(state_postLeadingTable.varmap, v) map ((d) => sql.ExprDisjunction(Set(d, constraint)))