--- a/src/main/scala/RDB2RDFMain.scala Wed Dec 16 15:15:32 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Wed Dec 16 16:29:59 2009 -0500
@@ -49,14 +49,14 @@
RelAlias(Name("R_" + v))
}
- def uriConstraint(constrainMe:RelAliasAttribute, u:ObjUri):Expression = {
+ def uriConstraint(constrainMe:RelAliasAttribute, u:ObjUri):PrimaryExpression = {
// println("equiv+= " + toString(constrainMe) + "=" + value)
- Expression(List(PrimaryExpressionEq(constrainMe,RValueTyped(SQLDatatype.INTEGER,Name(u.v.s)))))
+ PrimaryExpressionEq(constrainMe,RValueTyped(SQLDatatype.INTEGER,Name(u.v.s)))
}
- def literalConstraint(constrainMe:RelAliasAttribute, lit:SparqlLiteral, dt:SQLDatatype):Expression = {
+ def literalConstraint(constrainMe:RelAliasAttribute, lit:SparqlLiteral, dt:SQLDatatype):PrimaryExpression = {
// println("equiv+= " + toString(attr) + "=" + lit)
- Expression(List(PrimaryExpressionEq(constrainMe,RValueTyped(dt,Name(lit.lit.lexicalForm)))))
+ PrimaryExpressionEq(constrainMe,RValueTyped(dt,Name(lit.lit.lexicalForm)))
}
/** varConstraint
@@ -127,15 +127,12 @@
val objattr = RelAliasAttribute(relalias, attr)
// println(rel.n.s + " AS " + relalias.n.s)
- val sconstraint:Option[Expression] = s match {
- case SUri(u) => {
- uriConstraint(subjattr, u)
- None
- }
+ val sconstraint:List[PrimaryExpression] = s match {
+ case SUri(u) => List(uriConstraint(subjattr, u))
case SVar(v) => {
val binding:SQL2RDFValueMapper = varConstraint(subjattr, v, db, rel)
varmap += v -> binding
- None
+ List()
}
}
val sjoin = joined contains(relalias) match {
@@ -162,9 +159,9 @@
/* Literal foreign keys should probably throw an error,
* instead does what user meant. */
- case OLit(l) => List(joinconstraint) ::: literalConstraint(fkaliasattr, l, dt).conjuncts
+ case OLit(l) => List(joinconstraint) ::: List(literalConstraint(fkaliasattr, l, dt))
- case OUri(u) => List(joinconstraint) ::: uriConstraint(fkaliasattr, u).conjuncts
+ case OUri(u) => List(joinconstraint) ::: List(uriConstraint(fkaliasattr, u))
case OVar(v) => {
val binding = varConstraint(fkaliasattr, v, db, fkrel)
@@ -177,16 +174,16 @@
case false => {
sjoin match { // complex dance to keep joins ordered -- ouch!
- case Some(x) => joins = joins ::: List(Join(x, sconstraint))
+ case Some(x) => joins = joins ::: List(Join(x, Expression(sconstraint)))
case None =>
}
- joins = joins ::: List(Join(RelAsRelAlias(fkrel,oRelAlias), Some(Expression(conjuncts))))
+ joins = joins ::: List(Join(RelAsRelAlias(fkrel,oRelAlias), Expression(conjuncts)))
joined = joined + oRelAlias
}
case true => {
sjoin match {
- case Some(x) => joins = joins ::: List(Join(x, Some(Expression(conjuncts))))
+ case Some(x) => joins = joins ::: List(Join(x, Expression(conjuncts)))
case None =>
}
}
@@ -195,8 +192,8 @@
case Value(dt) => {
o match {
case OLit(l) => {
- val c = literalConstraint(objattr, l, dt).conjuncts
- exprs = exprs ::: c
+ val c = literalConstraint(objattr, l, dt)
+ exprs = exprs ::: List(c)
}
case OUri(u) => uriConstraint(objattr, u)
case OVar(v) => {
@@ -207,7 +204,7 @@
}
}
sjoin match {
- case Some(x) => joins = joins ::: List(Join(x, sconstraint))
+ case Some(x) => joins = joins ::: List(Join(x, Expression(sconstraint)))
case None =>
}
@@ -313,16 +310,12 @@
/* Add null guards for attributes associated with variables which
* are not optional and have not been used in constraints. */
r2rState.allVars.foreach(s => exprs = nullGuard(exprs, inConstraint, r2rState.varmap, s))
- val where = exprs.size match {
- case 0 => None
- case _ => Some(Expression(exprs))
- }
/* Construct the generated query as an abstract syntax. */
Select(
AttributeList(attrlist),
TableList(r2rState.joins),
- where
+ Expression(exprs)
)
}
}
--- a/src/test/scala/SQLTest.scala Wed Dec 16 15:15:32 2009 -0500
+++ b/src/test/scala/SQLTest.scala Wed Dec 16 16:29:59 2009 -0500
@@ -19,16 +19,16 @@
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_managName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None),
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),Expression(List())),
Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
- Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("id"))),
- RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("manager"))))))))))),
- Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("lastName")))),
- PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("lastName"))))))))
+ Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),
+ Attribute(Name("id"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("manager")))))))))),
+ Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("lastName")))),
+ PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_manager")),
+ Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -42,12 +42,12 @@
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None))),
- Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("manager"))),
- RValueTyped(SQLDatatype.INTEGER,Name("18"))),
- PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("lastName"))))))))
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),Expression(List())))),
+ Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("manager"))),
+ RValueTyped(SQLDatatype.INTEGER,Name("18"))),
+ PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -63,16 +63,16 @@
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None),
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),Expression(List())),
Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
- Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("manager"))),
- RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("id"))))),
- PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("lastName"))),
- RValueTyped(SQLDatatype.STRING,Name("Johnson"))))))))),
- Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName"))))))))
+ Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("manager"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),
+ Attribute(Name("id"))))),
+ PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),
+ Attribute(Name("lastName"))),
+ RValueTyped(SQLDatatype.STRING,Name("Johnson")))))))),
+ Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -93,23 +93,23 @@
AttrAlias(Name("A_empName"))),
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_grandManager")),Attribute(Name("lastName"))),
AttrAlias(Name("A_grandManagName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None),
- Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_lower"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("id"))))))))),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manager"))))), PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("birthday"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("birthday"))))))))),
- Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_upper"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_upper")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))))))))),
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),Expression(List())),
+ Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_lower"))),Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("id")))))))),
+ Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manager"))))), PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("birthday"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("birthday")))))))),
+ Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_upper"))),Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_upper")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id")))))))),
Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_grandManager"))),
- Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_grandManager")),
- Attribute(Name("id"))),
- RValueAttr(RelAliasAttribute(RelAlias(Name("R_upper")),
- Attribute(Name("manager"))))),
- PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_grandManager")),
- Attribute(Name("birthday"))),
- RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("birthday"))))))))))),
- Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("lastName")))),
- PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_grandManager")),
- Attribute(Name("lastName"))))))))
+ Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+ Attribute(Name("id"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_upper")),
+ Attribute(Name("manager"))))),
+ PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+ Attribute(Name("birthday"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),
+ Attribute(Name("birthday")))))))))),
+ Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
+ Attribute(Name("lastName")))),
+ PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+ Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}