--- a/src/test/scala/RDB2RDFTest.scala Wed Dec 16 16:29:59 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Wed Dec 16 17:08:03 2009 -0500
@@ -42,7 +42,8 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.id AS A_emp
FROM Employee AS R_emp
- INNER JOIN Employee AS R_id18 ON R_id18.id=R_emp.manager AND R_id18.id=18
+ INNER JOIN Employee AS R_id18
+ WHERE R_id18.id=R_emp.manager AND R_id18.id=18
""").get
assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
true
@@ -61,7 +62,8 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.id AS A_emp
FROM Employee AS R_emp
- INNER JOIN Employee AS R_18 ON R_18.id=R_emp.manager AND R_18.id=18
+ INNER JOIN Employee AS R_18
+ WHERE R_18.id=R_emp.manager AND R_18.id=18
""").get
assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
true
@@ -80,8 +82,8 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_manageName
FROM Employee AS R_emp
- INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
- WHERE R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
+ INNER JOIN Employee AS R_manager
+ WHERE R_manager.id=R_emp.manager AND R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
""").get
assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
}
@@ -98,8 +100,8 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.lastName AS A_empName
FROM Employee AS R_emp
- INNER JOIN Employee AS R_id18 ON R_id18.id=R_emp.manager AND R_id18.id=18
- WHERE R_emp.lastName IS NOT NULL
+ INNER JOIN Employee AS R_id18
+ WHERE R_id18.id=R_emp.manager AND R_id18.id=18 AND R_emp.lastName IS NOT NULL
""").get
assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
}
@@ -118,8 +120,8 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.lastName AS A_empName
FROM Employee AS R_emp
- INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
-WHERE R_manager.lastName="Johnson" AND R_emp.lastName IS NOT NULL
+ INNER JOIN Employee AS R_manager
+WHERE R_manager.id=R_emp.manager AND R_manager.lastName="Johnson" AND R_emp.lastName IS NOT NULL
""").get
assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
}
@@ -144,11 +146,11 @@
val sqlSelect = sqlParser.parseAll(sqlParser.select, """
SELECT R_emp.lastName AS A_empName, R_grandManager.lastName AS A_grandManagName
FROM Employee AS R_emp
- INNER JOIN Manage AS R_lower ON R_emp.id=R_lower.manages
- INNER JOIN Employee AS R_manager ON R_manager.id=R_lower.manager
- INNER JOIN Manage AS R_upper ON R_manager.id=R_upper.manages
- INNER JOIN Employee AS R_grandManager ON R_grandManager.id=R_upper.manager
- WHERE R_manager.birthday < R_emp.birthday AND R_grandManager.birthday < R_manager.birthday AND R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
+ INNER JOIN Manage AS R_lower
+ INNER JOIN Employee AS R_manager
+ INNER JOIN Manage AS R_upper
+ INNER JOIN Employee AS R_grandManager
+ WHERE R_emp.id=R_lower.manages AND R_manager.id=R_lower.manager AND R_manager.id=R_upper.manages AND R_grandManager.id=R_upper.manager AND R_manager.birthday < R_emp.birthday AND R_grandManager.birthday < R_manager.birthday AND R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
""").get
assert(RDB2RDF(db2, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
}
--- a/src/test/scala/SQLTest.scala Wed Dec 16 16:29:59 2009 -0500
+++ b/src/test/scala/SQLTest.scala Wed Dec 16 17:08:03 2009 -0500
@@ -10,8 +10,8 @@
val e = """
SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_managName
FROM Employee AS R_emp
- INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
- WHERE R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
+ INNER JOIN Employee AS R_manager
+ WHERE R_manager.id=R_emp.manager AND R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
"""
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
@@ -19,16 +19,13 @@
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_managName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),Expression(List())),
- 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_emp")),
- Attribute(Name("manager")))))))))),
- Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("lastName")))),
- PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_manager")),
- Attribute(Name("lastName")))))))
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
+ 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_emp")),Attribute(Name("manager"))))),
+ 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 +39,10 @@
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"))),Expression(List())))),
- Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),
- Attribute(Name("manager"))),
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))))),
+ 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")))))))
+ PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -56,23 +51,19 @@
val e = """
SELECT R_emp.lastName AS A_empName
FROM Employee AS R_emp
- INNER JOIN Employee AS R_manager ON R_emp.manager=R_manager.id
- AND R_manager.lastName="Johnson"
-WHERE R_emp.lastName IS NOT NULL
+ INNER JOIN Employee AS R_manager
+WHERE R_emp.manager=R_manager.id AND R_manager.lastName="Johnson" AND R_emp.lastName IS NOT NULL
"""
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"))),Expression(List())),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
- 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")))))))
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
+ Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager")))))),
+ 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"))),
+ PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName")))))))
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -81,35 +72,39 @@
val e = """
SELECT R_emp.lastName AS A_empName, R_grandManager.lastName AS A_grandManagName
FROM Employee AS R_emp
- INNER JOIN Manage AS R_lower ON R_lower.manages=R_emp.id
- INNER JOIN Employee AS R_manager ON R_manager.id=R_lower.manager
- AND R_manager.birthday < R_emp.birthday
- INNER JOIN Manage AS R_upper ON R_upper.manages=R_manager.id
- INNER JOIN Employee AS R_grandManager ON R_grandManager.id=R_upper.manager
- AND R_grandManager.birthday < R_manager.birthday
- WHERE R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
+ INNER JOIN Manage AS R_lower
+ INNER JOIN Employee AS R_manager
+ INNER JOIN Manage AS R_upper
+ INNER JOIN Employee AS R_grandManager
+ WHERE R_lower.manages=R_emp.id AND R_manager.id=R_lower.manager
+ AND R_manager.birthday < R_emp.birthday
+ AND R_upper.manages=R_manager.id AND R_grandManager.id=R_upper.manager
+ AND R_grandManager.birthday < R_manager.birthday
+ AND R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
"""
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")), Attribute(Name("lastName"))),
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"))),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"))),
- 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")))))))
+ TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
+ Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_lower")))),
+ Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager")))),
+ Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_upper")))),
+ Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_grandManager")))))),
+ Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manages"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("id"))))),
+ 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"))))),
+ PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_upper")),Attribute(Name("manages"))),
+ RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))))),
+ 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"))))),
+ 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))
}