--- a/src/main/scala/RDB2RDFMain.scala Thu Dec 17 00:40:45 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Thu Dec 17 11:56:05 2009 -0500
@@ -165,9 +165,11 @@
case OLit(l) => exprs += literalConstraint(objattr, l, dt)
case OUri(u) => exprs += uriConstraint(objattr, u)
case OVar(v) => {
- // !! 2nd+ ref implies constraint
val binding = varConstraint(objattr, v, db, rel)
- varmap += v -> binding
+ if (varmap.contains(v))
+ exprs += PrimaryExpressionEq(varToAttribute(varmap, v), RValueAttr(objattr))
+ else
+ varmap += v -> binding
}
}
}
--- a/src/test/scala/RDB2RDFTest.scala Thu Dec 17 00:40:45 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Thu Dec 17 11:56:05 2009 -0500
@@ -49,6 +49,24 @@
true
}
+ test("<s> <p> ?x") {
+ val sparqlParser = Sparql()
+ val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
+SELECT ?manager {
+<http://hr.example/DB/Employee/id.18#record> <http://hr.example/DB/Employee#manager> ?manager
+}
+""").get
+ val sqlParser = Sql()
+ val sqlSelect = sqlParser.parseAll(sqlParser.select, """
+SELECT R_manager.id AS A_manager
+ FROM Employee AS R_id18
+ INNER JOIN Employee AS R_manager
+ WHERE R_manager.id=R_id18.manager AND R_id18.id=18 AND R_manager.id IS NOT NULL
+""").get
+ assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
+ true
+ }
+
test("?s <p> 18") {
/* Literal foreign keys should probably throw an error,
* instead does what user meant. */
@@ -69,6 +87,25 @@
true
}
+ test("?s1 <p> ?x . ?s2 <p> ?x") {
+ val sparqlParser = Sparql()
+ val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
+SELECT ?emp1 ?emp2 ?sharedName {
+ ?emp1 <http://hr.example/DB/Employee#lastName> ?sharedName .
+ ?emp2 <http://hr.example/DB/Employee#lastName> ?sharedName
+}
+""").get
+ val sqlParser = Sql()
+ val sqlSelect = sqlParser.parseAll(sqlParser.select, """
+SELECT R_emp1.id AS A_emp1, R_emp2.id AS A_emp2, R_emp1.lastName AS A_sharedName
+ FROM Employee AS R_emp1
+ INNER JOIN Employee AS R_emp2
+ WHERE R_emp1.lastName=R_emp2.lastName AND R_emp1.id IS NOT NULL AND R_emp1.lastName IS NOT NULL AND R_emp2.id IS NOT NULL
+""").get
+ assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
+ true
+ }
+
test("transform SQLbgp") {
val sparqlParser = Sparql()
val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """