--- a/src/main/scala/RDB2RDFMain.scala Tue Dec 15 14:18:36 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Tue Dec 15 15:05:12 2009 -0500
@@ -158,7 +158,8 @@
val conjuncts = o match {
- /* OList Should probably throw an error, instead does what user meant. */
+ /* Literal foreign keys should probably throw an error,
+ * instead does what user meant. */
case OLit(l) => List(joinconstraint) ::: literalConstraint(l, pk).conjuncts
case OUri(u) => List(joinconstraint) ::: uriConstraint(u, pk).conjuncts
@@ -180,15 +181,14 @@
}
case Value(dt) => {
o match {
+ case OLit(l) => literalConstraint(l, pk)
case OUri(u) => uriConstraint(u, pk)
case OVar(v) => {
allVars = allVars ::: List(v)
// !! 2nd+ ref implies constraint
val binding = varConstraint(v, db, rel, relalias, attr)
varmap += v -> binding
- // println(toString(binding))
}
- case OLit(l) => literalConstraint(l, pk)
}
}
}
@@ -228,6 +228,8 @@
def apply (db:DatabaseDesc, sparql:SparqlSelect, stem:StemURI, pk:PrimaryKey) : Select = {
val SparqlSelect(attrs, triples) = sparql
+
+ /* Create an object to hold our compilation state. */
var r2rState = R2RState(
Set[RelAlias](),
List[Var](),
@@ -236,11 +238,16 @@
Map[Var, SQL2RDFValueMapper]()
)
+ /* Examine each triple, updating the compilation state. */
triples.triplepatterns.foreach(s => r2rState = acc(db, r2rState, s, pk))
+ /* Select the attributes corresponding to the variables
+ * in the SPARQL SELECT. */
var attrlist:List[NamedAttribute] = List()
attrs.attributelist.foreach(s => attrlist = attrlist ::: List(project(r2rState.varmap, s)))
+ /* Add null guards for attributes associated with variables which
+ * are not optional and have not been used in constraints. */
var notNulls:List[PrimaryExpressionNotNull] = List()
r2rState.allVars.foreach(s => notNulls = nullGuard(notNulls, r2rState.inConstraint, r2rState.varmap, s))
val where = notNulls.size match {
@@ -248,6 +255,7 @@
case _ => Some(Expression(notNulls))
}
+ /* Construct the generated query as an abstract syntax. */
Select(
AttributeList(attrlist),
TableList(r2rState.joins),
--- a/src/test/scala/RDB2RDFTest.scala Tue Dec 15 14:18:36 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Tue Dec 15 15:05:12 2009 -0500
@@ -33,6 +33,8 @@
}
test("?s <p> 18") {
+ /* Literal foreign keys should probably throw an error,
+ * instead does what user meant. */
val sparqlParser = Sparql()
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
SELECT ?emp {