--- a/src/test/scala/SQLTest.scala Sun Jun 13 19:31:21 2010 -0400
+++ b/src/test/scala/SQLTest.scala Sun Jun 13 19:32:44 2010 -0400
@@ -54,10 +54,12 @@
val e = """
SELECT 1 AS _TEST_
"""
- val expected = Select(AttributeList(Set(NamedAttribute(PrimaryExpressionTyped(Datatype.INTEGER,Name("1")),
- AttrAlias(Name("_TEST_"))))),
- TableList(AddOrderedSet()),
- None)
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(PrimaryExpressionTyped(Datatype.INTEGER,Name("1")),
+ AttrAlias(Name("_TEST_"))))),
+ TableList(AddOrderedSet()),
+ None, List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -70,14 +72,17 @@
INNER JOIN Employee AS R_manager
WHERE R_manager.id=R_emp.manager
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
- Some(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
+ Some(
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -89,14 +94,17 @@
FROM Employee AS R_emp
INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
- Some(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
+ Some(
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -109,19 +117,22 @@
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(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_manager")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_managName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
- Some(ExprConjunction(Set(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName")))))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_manager")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_managName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
+ Some(ExprConjunction(Set(
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -132,13 +143,16 @@
FROM Employee AS R_emp
WHERE R_emp.manager=18 AND R_emp.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))),
- PrimaryExpressionTyped(Datatype.INTEGER,Name("18"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))),
+ PrimaryExpressionTyped(Datatype.INTEGER,Name("18"))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -150,16 +164,19 @@
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(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName")))),
- PrimaryExpressionTyped(Datatype.STRING,Name("Johnson"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("manager")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName")))),
+ PrimaryExpressionTyped(Datatype.STRING,Name("Johnson"))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -178,29 +195,32 @@
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(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")), Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("lastName"))),
- AttrAlias(Name("A_grandManagName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_lower"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None),
- InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_upper"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_grandManager"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),Attribute(Name("manages")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id"))))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),Attribute(Name("manager"))))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("birthday")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("birthday"))))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),Attribute(Name("manages")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("id")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),Attribute(Name("manager"))))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("birthday")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("birthday"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("lastName")))))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")), Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("lastName"))),
+ AttrAlias(Name("A_grandManagName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_lower"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_upper"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_grandManager"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),Attribute(Name("manages")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),Attribute(Name("manager"))))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("birthday")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("birthday"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),Attribute(Name("manages")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("id")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),Attribute(Name("manager"))))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("birthday")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("birthday"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -222,37 +242,46 @@
) AS R_union1
WHERE R_union1.A_who=R_who.id AND R_who.lastName="Smith"
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_union1")), Attribute(Name("name"))),
- AttrAlias(Name("A_name"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_who"))), None),
- InnerJoin(AliasedResource(Subselect(Union(Set(
- Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_manager")), Attribute(Name("lastName"))),
- AttrAlias(Name("A_name"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_above")), Attribute(Name("manages"))),
- AttrAlias(Name("A_who"))))),
- TableList(AddOrderedSet(
- InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None)
- )),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("manager")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName"))))))))),
- Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_managed")), Attribute(Name("lastName"))),
- AttrAlias(Name("A_name"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_below")), Attribute(Name("manager"))),
- AttrAlias(Name("A_who"))))),
- TableList(AddOrderedSet(
- InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_below"))), None),
- InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_managed"))), None)
- )),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_below")),Attribute(Name("manages")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),Attribute(Name("id"))))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),Attribute(Name("lastName")))))))))))),
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_union1")), Attribute(Name("name"))),
+ AttrAlias(Name("A_name"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_who"))), None),
+ InnerJoin(AliasedResource(Subselect(Union(Set(
+ Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_manager")), Attribute(Name("lastName"))),
+ AttrAlias(Name("A_name"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_above")), Attribute(Name("manages"))),
+ AttrAlias(Name("A_who"))))),
+ TableList(AddOrderedSet(
+ InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_manager"))), None)
+ )),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("manager")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("id"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None),
+ Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_managed")), Attribute(Name("lastName"))),
+ AttrAlias(Name("A_name"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_below")), Attribute(Name("manager"))),
+ AttrAlias(Name("A_who"))))),
+ TableList(AddOrderedSet(
+ InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_below"))), None),
+ InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_managed"))), None)
+ )),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_below")),Attribute(Name("manages")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),Attribute(Name("id"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),Attribute(Name("lastName")))))))),
+ List[OrderElt](), None, None)))),
RelVar(Name("R_union1"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_union1")),Attribute(Name("A_who")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),Attribute(Name("id"))))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),Attribute(Name("lastName")))),
- PrimaryExpressionTyped(Datatype.STRING,Name("Smith")))))))
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_union1")),Attribute(Name("A_who")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),Attribute(Name("id"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),Attribute(Name("lastName")))),
+ PrimaryExpressionTyped(Datatype.STRING,Name("Smith")))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -263,14 +292,17 @@
FROM Manage AS R_above
WHERE R_above.id IS NOT NULL
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
- Attribute(Name("manages"))),
- AttrAlias(Name("A_who"))),
- NamedAttribute(ConstNULL(),
- AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
- Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
+ Attribute(Name("manages"))),
+ AttrAlias(Name("A_who"))),
+ NamedAttribute(ConstNULL(),
+ AttrAlias(Name("A_bday"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
+ Some(
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -281,16 +313,17 @@
SELECT CONCAT(""" + QuotedBaseURI + """, "Employee", "/", "id", ".", R_emp.id, "#record") AS A_emp
FROM Employee AS R_emp
"""
- val expected = Select(AttributeList(Set(NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
- PrimaryExpressionTyped(Datatype("String"),Name("Employee")),
- PrimaryExpressionTyped(Datatype("String"),Name("/")),
- PrimaryExpressionTyped(Datatype("String"),Name("id")),
- PrimaryExpressionTyped(Datatype("String"),Name(".")),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))),
- PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
- AttrAlias(Name("A_emp"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
- None)
+ val expected = Select(
+ false, AttributeList(Set(NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
+ PrimaryExpressionTyped(Datatype("String"),Name("Employee")),
+ PrimaryExpressionTyped(Datatype("String"),Name("/")),
+ PrimaryExpressionTyped(Datatype("String"),Name("id")),
+ PrimaryExpressionTyped(Datatype("String"),Name(".")),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))),
+ PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
+ AttrAlias(Name("A_emp"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ None, List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -301,21 +334,24 @@
FROM Manage AS R_above
WHERE (R_above.id IS NOT NULL) OR (R_above.id < 5 AND R_above.id < 3)
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
- Attribute(Name("manages"))),
- AttrAlias(Name("A_who"))),
- NamedAttribute(ConstNULL(),
- AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
- Some(
- ExprDisjunction(Set(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id"))))),
- ExprConjunction(Set(
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
- PrimaryExpressionTyped(Datatype.INTEGER,Name("5"))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
- PrimaryExpressionTyped(Datatype.INTEGER,Name("3")))
- ))))))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
+ Attribute(Name("manages"))),
+ AttrAlias(Name("A_who"))),
+ NamedAttribute(ConstNULL(),
+ AttrAlias(Name("A_bday"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
+ Some(
+ ExprDisjunction(Set(
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id"))))),
+ ExprConjunction(Set(
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
+ PrimaryExpressionTyped(Datatype.INTEGER,Name("5"))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
+ PrimaryExpressionTyped(Datatype.INTEGER,Name("3")))
+ ))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -327,20 +363,23 @@
LEFT OUTER JOIN Manage AS R_mang ON R_mang.emp=R_emp.id
WHERE R_emp.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),
- Attribute(Name("manageName"))),
- AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- LeftOuterJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_mang"))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("emp")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id"))))
- )))),
- Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))
- ))
+ val expected = Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("A_empName"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),
+ Attribute(Name("manageName"))),
+ AttrAlias(Name("A_manageName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ LeftOuterJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_mang"))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("emp")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id"))))
+ )))),
+ Some(
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))
+ ),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -356,18 +395,23 @@
WHERE R_emp.lastName IS NOT NULL
"""
val expected =
- Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))),AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("manageName"))),AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
- LeftOuterJoin(AliasedResource(
- Subselect(Select(AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))),AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("manageName"))),AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
- None)),
- RelVar(Name("R_mang"))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("emp")))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))))))),
- Some(RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))
+ Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))),AttrAlias(Name("A_empName"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("manageName"))),AttrAlias(Name("A_manageName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None),
+ LeftOuterJoin(AliasedResource(
+ Subselect(Select(
+ false,
+ AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName"))),AttrAlias(Name("A_empName"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("manageName"))),AttrAlias(Name("A_manageName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ None, List[OrderElt](), None, None)),
+ RelVar(Name("R_mang"))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),Attribute(Name("emp")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))))))),
+ Some(RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))),
+ List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -496,22 +540,24 @@
R_emp.lastName AS O
FROM Employee AS R_emp
""" // "
- val expected = View(Relation(Name("triples")), Select(AttributeList(Set(
- NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
- PrimaryExpressionTyped(Datatype("String"),Name("Employee")),
- PrimaryExpressionTyped(Datatype("String"),Name("/")),
- PrimaryExpressionTyped(Datatype("String"),Name("empid")),
- PrimaryExpressionTyped(Datatype("String"),Name(".")),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))),
- PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
- AttrAlias(Name("S"))),
- NamedAttribute(PrimaryExpressionTyped(Datatype.STRING,Name("<http://hr.example/DB/Employee#lastName>")),
- AttrAlias(Name("P"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
- AttrAlias(Name("O"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
- None))
+ val expected = View(Relation(Name("triples")), Select(
+ false,
+ AttributeList(Set(
+ NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
+ PrimaryExpressionTyped(Datatype("String"),Name("Employee")),
+ PrimaryExpressionTyped(Datatype("String"),Name("/")),
+ PrimaryExpressionTyped(Datatype("String"),Name("empid")),
+ PrimaryExpressionTyped(Datatype("String"),Name(".")),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("id")))),
+ PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
+ AttrAlias(Name("S"))),
+ NamedAttribute(PrimaryExpressionTyped(Datatype.STRING,Name("<http://hr.example/DB/Employee#lastName>")),
+ AttrAlias(Name("P"))),
+ NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ Attribute(Name("lastName"))),
+ AttrAlias(Name("O"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ None, List[OrderElt](), None, None))
assert(expected === (a.parseAll(a.createview, e).get))
}
--- a/src/test/scala/SparqlToSparqlToSqlTest.scala Sun Jun 13 19:31:21 2010 -0400
+++ b/src/test/scala/SparqlToSparqlToSqlTest.scala Sun Jun 13 19:32:44 2010 -0400
@@ -5,6 +5,7 @@
package w3c.sw
import org.scalatest.FunSuite
+import scala.util.matching.Regex
import java.net.URI
import w3c.sw.sparql.Sparql
import w3c.sw.sparql2sparql.{SparqlToSparql}
@@ -333,29 +334,156 @@
"""
}
- // test("hospital as view") {
- // val sparqlParser = Sparql()
- // println("hospital view...")
- // val view = toView(List(db2hl7), hosp1, StemURI("http://hospital.example/DB/"))
- // println("hospital view: " + view)
-// val sqlParser = Sql()
-// val expected = sqlParser.parseAll(sqlParser.createview, """
-// """).get
-// assert(expected === view)
- // }
+/*
+ test("hospital as view") {
+ val sparqlParser = Sparql()
+ println("hospital view...")
+ val view = toView(List(db2hl7), hosp1, StemURI("http://hospital.example/DB/"))
+ println("hospital view: " + view)
+ val sqlParser = Sql()
+ val expected = sqlParser.parseAll(sqlParser.createview, """
+""").get
+ assert(expected === view)
+ }
+ */
- /* ========== DiabeticPatient database tests ==========
+ /* ========== BSBM database tests ==========
*
*/
val bsbmDdl = """
-CREATE TABLE Person (ID INT PRIMARY KEY, MiddleName STRING, DateOfBirth DATE, SexDE INT, PRIMARY KEY (ID), FOREIGN KEY (SexDE) REFERENCES Sex_DE(ID));
-CREATE TABLE Sex_DE (ID INT PRIMARY KEY, EntryName STRING);
-CREATE TABLE Item_Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), PatientID INT, FOREIGN KEY (PatientID) REFERENCES Person(ID), PerformedDTTM DATE, EntryName STRING);
-CREATE TABLE Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), ItemID INT, FOREIGN KEY (ItemID) REFERENCES Item_Medication(ID), MedDictDE INT, FOREIGN KEY (MedDictDE) REFERENCES Medication_DE(ID), DaysToTake INT);
-CREATE TABLE Medication_DE (ID INT PRIMARY KEY, NDC INT);
-CREATE TABLE NDCcodes (ID INT PRIMARY KEY, NDC INT, ingredient INT);
+CREATE TABLE offer (
+ nr INT,
+ product INT,
+ producer INT,
+ vendor INT,
+ price DOUBLE,
+ validFrom DATETIME,
+ validTo DATETIME,
+ deliveryDays INT,
+ offerWebpage STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE person (
+ nr INT,
+ name STRING,
+ mbox_sha1sum STRING,
+ country STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE producer (
+ nr INT,
+ label STRING,
+ comment STRING,
+ homepage STRING,
+ country STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE product (
+ nr INT,
+ label STRING,
+ comment STRING,
+ producer INT,
+ propertyNum1 INT,
+ propertyNum2 INT,
+ propertyNum3 INT,
+ propertyNum4 INT,
+ propertyNum5 INT,
+ propertyNum6 INT,
+ propertyTex1 STRING,
+ propertyTex2 STRING,
+ propertyTex3 STRING,
+ propertyTex4 STRING,
+ propertyTex5 STRING,
+ propertyTex6 STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE productfeature (
+ nr INT,
+ label STRING,
+ comment STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE productfeatureproduct (
+ product INT,
+ productFeature INT,
+ PRIMARY KEY (productFeature)
+);
+
+
+CREATE TABLE producttype (
+ nr INT,
+ label STRING,
+ comment STRING,
+ parent INT,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE producttypeproduct (
+ product INT,
+ productType INT,
+ PRIMARY KEY (productType)
+);
+
+
+CREATE TABLE review (
+ nr INT,
+ product INT,
+ producer INT,
+ person INT,
+ reviewDate DATETIME,
+ title STRING,
+ text STRING,
+ language STRING,
+ rating1 INT,
+ rating2 INT,
+ rating3 INT,
+ rating4 INT,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
+
+
+CREATE TABLE vendor (
+ nr INT,
+ label STRING,
+ comment STRING,
+ homepage STRING,
+ country STRING,
+ publisher INT,
+ publishDate DATE,
+ PRIMARY KEY (nr)
+);
"""
+ /*
+ productfeatureproduct ( PRIMARY KEY (product,productFeature) );
+ producttypeproduct ( PRIMARY KEY (product,productType) );
+ */
val bsbmDb:DatabaseDesc = DDLParser.parseAll(DDLParser.ddl, bsbmDdl).get
+
val delme = Sparql() // re-use ConstructParser ?
val db2bsbm = delme.parseAll(delme.construct, """
PREFIX map: <file:/E:/code/d2r-server-0.4/d2r-mapping.n3#>
@@ -384,14 +512,21 @@
PREFIX tr: <http://www.w3.org/2008/04/SPARQLfed/#>
CONSTRUCT {
-<s> <p> <o> .
+ ?product a bsbm:Product .
+ ?product bsbm:productFeature ?pfp .
+ ?product rdf:type ?ptp .
+ ?product rdfs:label ?p_label .
+ ?product bsbm:productPropertyNumeric1 ?lit_propertyNum1 .
} WHERE {
-<s> <p> <o> .
+ ?product product:label ?p_label .
+ ?product product:propertyNum1 ?lit_propertyNum1 .
+ ?pfp productfeatureproduct:product ?product .
+ ?ptp producttypeproduct:product ?product .
}""" //"
).get
test("bsbm1") {
val sparqlParser = Sparql()
- val bsbmQuery = sparqlParser.parseAll(sparqlParser.select, """
+ val queryStr = """
PREFIX bsbm-inst: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/>
PREFIX bsbm: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@@ -408,28 +543,55 @@
}
ORDER BY ?label
LIMIT 10
+"""
+ .replaceAll("<http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductFeature([0-9]+)>",
+ "<http://bsbm.example/db/productfeatureproduct/productFeature.$1#record>")
+ .replaceAll("<http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType([0-9]+)>",
+ "<http://bsbm.example/db/producttypeproduct/productType.$1#record>")
+
+ val bsbmQuery = sparqlParser.parseAll(sparqlParser.select, queryStr).get
+
+ val stemExpected = sparqlParser.parseAll(sparqlParser.select, """
+PREFIX product: <http://bsbm.example/db/product#>
+PREFIX pfp: <http://bsbm.example/db/productfeatureproduct#>
+PREFIX ptp: <http://bsbm.example/db/producttypeproduct#>
+
+SELECT DISTINCT ?product ?label WHERE {
+ ?product product:label ?label .
+ ?product product:propertyNum1 ?value1 .
+ <http://bsbm.example/db/producttypeproduct/productType.59#record> ptp:product ?product .
+ <http://bsbm.example/db/productfeatureproduct/productFeature.5#record> pfp:product ?product .
+ <http://bsbm.example/db/productfeatureproduct/productFeature.7#record> pfp:product ?product .
+ FILTER (?value1 > 578)
+}
+ORDER BY ?label
+LIMIT 10
""").get
- val stemQuery = sparqlParser.parseAll(sparqlParser.select, """
-SELECT ?o WHERE { ?s <p> ?o }
-""").get
val sqlParser = Sql()
- val sqlQuery = sqlParser.parseAll(sqlParser.select, """
-SELECT R_emp.empid AS emp
- FROM Employee AS R_emp
- WHERE R_emp.empid IS NOT NULL AND R_emp.lastName="Smith"
+ val sqlExpected = sqlParser.parseAll(sqlParser.select, """
+SELECT DISTINCT R_product.label AS label, R_product.nr AS product
+ FROM product AS R_product
+ INNER JOIN producttypeproduct AS R_productType59
+ ON R_productType59.product=R_product.nr
+ AND R_productType59.productType=59
+ INNER JOIN productfeatureproduct AS R_productFeature5
+ ON R_productFeature5.product=R_product.nr
+ AND R_productFeature5.productFeature=5
+ INNER JOIN productfeatureproduct AS R_productFeature7
+ ON R_productFeature7.product=R_product.nr
+ AND R_productFeature7.productFeature=7
+ WHERE R_product.propertyNum1 > 578
+ AND R_product.label IS NOT NULL
+ORDER BY R_product.label
+LIMIT 10
""").get
-// val asStem = SparqlToSparql(bsbmQuery, List(db2bsbm))
-// if (!(asStem == stemQuery)) {
-// println(asStem.toString())
-// println("---")
-// println(stemQuery.toString())
-// }
-// assert(asStem == stemQuery)
-// val asSql = SparqlToSql(bsbmDb, asStem, StemURI("http://hospital.example/DB/"), false, false)._1
-// assert(asSql === sqlQuery)
-// val output = """
-// """
+ val asStem = SparqlToSparql(bsbmQuery, List(db2bsbm))
+ assert(stemExpected === asStem)
+ val (asSql, _) = SparqlToSql(bsbmDb, asStem, StemURI("http://bsbm.example/db/"), false, false)
+ assert(sqlExpected === asSql)
+ val output = """
+"""
}
}