--- a/src/test/scala/SQLTest.scala Wed Oct 13 23:21:16 2010 -0400
+++ b/src/test/scala/SQLTest.scala Thu Oct 14 08:31:17 2010 -0400
@@ -13,10 +13,10 @@
R_manager.id=R_emp.manager AND R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
"""
val expected = ExprConjunction(Set(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))))))
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))))))
assert(expected === (a.parseAll(a.expression, e).get))
}
@@ -27,10 +27,10 @@
R_manager.id=R_emp.manager OR R_emp.lastName IS NOT NULL OR R_manager.lastName IS NOT NULL
"""
val expected = ExprDisjunction(Set(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))))))
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))))))
assert(expected === (a.parseAll(a.expression, e).get))
}
@@ -41,10 +41,10 @@
( R_manager.id=R_emp.manager OR R_emp.lastName IS NOT NULL OR R_manager.lastName IS NOT NULL )
"""
val expected = ExprDisjunction(Set(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))))))
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))))))
assert(expected === (a.parseAll(a.expression, e).get))
}
@@ -75,19 +75,19 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None))),
Some(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
test("parse INNER JOIN ON") {
- // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
+ // AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
SELECT R_emp.lastName AS A_empName
@@ -97,19 +97,19 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None))),
Some(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
test("parse SQLbgp") {
- // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
+ // AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_managName
@@ -120,18 +120,18 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))),
ProjectAttribute(RelVarAttr(RelVar(Name("R_manager")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_managName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None))),
Some(ExprConjunction(Set(
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -146,12 +146,12 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("18"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -167,15 +167,15 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id")))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("manager"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id")))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))),
PrimaryExpressionTyped(Datatype.STRING,Name("Johnson"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -197,29 +197,29 @@
"""
val expected = Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")), AttrName("lastName")),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")), RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))),
- ProjectAttribute(RelVarAttr(RelVar(Name("R_grandManager")),AttrName("lastName")),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_grandManager")),RDB.AttrName("lastName")),
AttrAlias(Name("A_grandManagName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_lower"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None),
- InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_upper"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_grandManager"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),AttrName("manages"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id")))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),AttrName("manager")))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("birthday"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("birthday")))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),AttrName("manages"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id")))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),AttrName("id"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),AttrName("manager")))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),AttrName("birthday"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("birthday")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),AttrName("lastName"))))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_lower"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_upper"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_grandManager"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),RDB.AttrName("manages"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("id")))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_lower")),RDB.AttrName("manager")))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("birthday"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("birthday")))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),RDB.AttrName("manages"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id")))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),RDB.AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_upper")),RDB.AttrName("manager")))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),RDB.AttrName("birthday"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("birthday")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_grandManager")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -244,42 +244,42 @@
"""
val expected = Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_union1")), AttrName("name")),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_union1")), RDB.AttrName("name")),
AttrAlias(Name("A_name"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_who"))), None),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_who"))), None),
InnerJoin(AliasedResource(Subselect(Union(Set(
Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_manager")), AttrName("lastName")),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_manager")), RDB.AttrName("lastName")),
AttrAlias(Name("A_name"))),
- ProjectAttribute(RelVarAttr(RelVar(Name("R_above")), AttrName("manages")),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_above")), RDB.AttrName("manages")),
AttrAlias(Name("A_who"))))),
TableList(AddOrderedSet(
- InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_manager"))), None)
+ InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_above"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_manager"))), None)
)),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("manager"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("lastName"))))))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),RDB.AttrName("manager"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("id")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None),
Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_managed")), AttrName("lastName")),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_managed")), RDB.AttrName("lastName")),
AttrAlias(Name("A_name"))),
- ProjectAttribute(RelVarAttr(RelVar(Name("R_below")), AttrName("manager")),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_below")), RDB.AttrName("manager")),
AttrAlias(Name("A_who"))))),
TableList(AddOrderedSet(
- InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_below"))), None),
- InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_managed"))), None)
+ InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_below"))), None),
+ InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_managed"))), None)
)),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_below")),AttrName("manages"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),AttrName("id")))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),AttrName("lastName"))))))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_below")),RDB.AttrName("manages"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),RDB.AttrName("id")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_managed")),RDB.AttrName("lastName"))))))),
List[OrderElt](), None, None)))),
RelVar(Name("R_union1"))), None))),
- Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_union1")),AttrName("A_who"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),AttrName("id")))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),AttrName("lastName"))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_union1")),RDB.AttrName("A_who"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),RDB.AttrName("id")))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_who")),RDB.AttrName("lastName"))),
PrimaryExpressionTyped(Datatype.STRING,Name("Smith")))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
@@ -295,13 +295,13 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_above")),
- AttrName("manages")),
+ RDB.AttrName("manages")),
AttrAlias(Name("A_who"))),
ProjectAttribute(ConstNULL(),
AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_above"))), None))),
Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),RDB.AttrName("id"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -319,10 +319,10 @@
PrimaryExpressionTyped(Datatype("String"),Name("/")),
PrimaryExpressionTyped(Datatype("String"),Name("id")),
PrimaryExpressionTyped(Datatype("String"),Name(".")),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("id"))),
PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
AttrAlias(Name("A_emp"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None))),
None, List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -337,18 +337,18 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_above")),
- AttrName("manages")),
+ RDB.AttrName("manages")),
AttrAlias(Name("A_who"))),
ProjectAttribute(ConstNULL(),
AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_above"))), None))),
Some(
ExprDisjunction(Set(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id")))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),RDB.AttrName("id")))),
ExprConjunction(Set(
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),RDB.AttrName("id"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("5"))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),RDB.AttrName("id"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("3")))
))))),
List[OrderElt](), None, None)
@@ -366,18 +366,18 @@
val expected = Select(
false,
Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("A_empName"))),
ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),
- AttrName("manageName")),
+ RDB.AttrName("manageName")),
AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
- LeftOuterJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_mang"))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),AttrName("emp"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id")))
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
+ LeftOuterJoin(AliasedResource(RDB.RelName("Manage"),RelVar(Name("R_mang"))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),RDB.AttrName("emp"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("id")))
)))),
Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName"))))
),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
@@ -397,20 +397,20 @@
val expected =
Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")),AttrAlias(Name("A_empName"))),
- ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),AttrName("manageName")),AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")),AttrAlias(Name("A_empName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),RDB.AttrName("manageName")),AttrAlias(Name("A_manageName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None),
LeftOuterJoin(AliasedResource(
Subselect(Select(
false,
- Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName")),AttrAlias(Name("A_empName"))),
- ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),AttrName("manageName")),AttrAlias(Name("A_manageName"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName")),AttrAlias(Name("A_empName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),RDB.AttrName("manageName")),AttrAlias(Name("A_manageName"))))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None))),
None, List[OrderElt](), None, None)),
RelVar(Name("R_mang"))),
- RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),AttrName("emp"))),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id"))))))),
- Some(RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_mang")),RDB.AttrName("emp"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("id"))))))),
+ Some(RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("lastName"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -420,7 +420,7 @@
val e = """
ID INT PRIMARY KEY
"""
- val expected = FieldDesc(AttrName("ID"), Value(Datatype.INTEGER), true)
+ val expected = FieldDesc(RDB.AttrName("ID"), Value(Datatype.INTEGER), true)
assert(expected === (a.parseAll(a.fielddescorkeydef, e).get))
}
@@ -430,9 +430,9 @@
CREATE TABLE Sex_DE (ID INT PRIMARY KEY)
"""
val expected =
- (RelName("Sex_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER))))
+ (RDB.RelName("Sex_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER))))
assert(expected === (a.parseAll(a.createtable, e).get))
}
@@ -442,10 +442,10 @@
CREATE TABLE Sex_DE (ID INT PRIMARY KEY, EnterpriseEntryID INT)
"""
val expected = DatabaseDesc(
- Map(RelName("Sex_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
+ Map(RDB.RelName("Sex_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
assert(expected === (a.parseAll(a.ddl, e).get))
}
@@ -456,10 +456,10 @@
CREATE TABLE Sex_DE (ID INT, EnterpriseEntryID INT, PRIMARY KEY (ID))
"""
val expected = DatabaseDesc(
- Map(RelName("Sex_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
+ Map(RDB.RelName("Sex_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
assert(expected === (a.parseAll(a.ddl, e).get))
}
@@ -471,16 +471,16 @@
CREATE TABLE Sex_DE (ID INT PRIMARY KEY, EntryName STRING)
"""
val expected:DatabaseDesc = DatabaseDesc(
- Map(RelName("Person") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("MiddleName") -> Value(Datatype.STRING),
- AttrName("DateOfBirth") -> Value(Datatype.DATE),
- AttrName("SexDE") -> ForeignKey(RelName("Sex_DE"), AttrName("ID")))),
- RelName("Sex_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("EntryName") -> Value(Datatype.STRING)))
+ Map(RDB.RelName("Person") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("MiddleName") -> Value(Datatype.STRING),
+ RDB.AttrName("DateOfBirth") -> Value(Datatype.DATE),
+ RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID")))),
+ RDB.RelName("Sex_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("EntryName") -> Value(Datatype.STRING)))
))
assert(expected === (a.parseAll(a.ddl, e).get))
}
@@ -496,42 +496,42 @@
CREATE TABLE NDCcodes (ID INT PRIMARY KEY, NDC INT, ingredient INT);
"""
val expected:DatabaseDesc = DatabaseDesc(
- Map(RelName("Person") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("MiddleName") -> Value(Datatype.STRING),
- AttrName("DateOfBirth") -> Value(Datatype.DATE),
- AttrName("SexDE") -> ForeignKey(RelName("Sex_DE"), AttrName("ID")))),
- RelName("Sex_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("EntryName") -> Value(Datatype.STRING))),
- RelName("Item_Medication") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("PatientID") -> ForeignKey(RelName("Person"), AttrName("ID")),
- AttrName("PerformedDTTM") -> Value(Datatype.DATE),
- AttrName("EntryName") -> Value(Datatype.STRING))),
- RelName("Medication") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("ItemID") -> ForeignKey(RelName("Item_Medication"), AttrName("ID")),
- AttrName("MedDictDE") -> ForeignKey(RelName("Medication_DE"), AttrName("ID")))),
- RelName("Medication_DE") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("NDC") -> Value(Datatype.INTEGER))),
- RelName("NDCcodes") ->
- RelationDesc(Option(AttrName("ID")),
- Map(AttrName("ID") -> Value(Datatype.INTEGER),
- AttrName("NDC") -> Value(Datatype.INTEGER),
- AttrName("ingredient") -> Value(Datatype.INTEGER)))
+ Map(RDB.RelName("Person") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("MiddleName") -> Value(Datatype.STRING),
+ RDB.AttrName("DateOfBirth") -> Value(Datatype.DATE),
+ RDB.AttrName("SexDE") -> ForeignKey(RDB.RelName("Sex_DE"), RDB.AttrName("ID")))),
+ RDB.RelName("Sex_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("EntryName") -> Value(Datatype.STRING))),
+ RDB.RelName("Item_Medication") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("PatientID") -> ForeignKey(RDB.RelName("Person"), RDB.AttrName("ID")),
+ RDB.AttrName("PerformedDTTM") -> Value(Datatype.DATE),
+ RDB.AttrName("EntryName") -> Value(Datatype.STRING))),
+ RDB.RelName("Medication") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("ItemID") -> ForeignKey(RDB.RelName("Item_Medication"), RDB.AttrName("ID")),
+ RDB.AttrName("MedDictDE") -> ForeignKey(RDB.RelName("Medication_DE"), RDB.AttrName("ID")))),
+ RDB.RelName("Medication_DE") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("NDC") -> Value(Datatype.INTEGER))),
+ RDB.RelName("NDCcodes") ->
+ RelationDesc(Option(RDB.AttrName("ID")),
+ Map(RDB.AttrName("ID") -> Value(Datatype.INTEGER),
+ RDB.AttrName("NDC") -> Value(Datatype.INTEGER),
+ RDB.AttrName("ingredient") -> Value(Datatype.INTEGER)))
))
assert(expected === (a.parseAll(a.ddl, e).get))
}
test("CREATE VIEW") {
- // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
+ // AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
CREATE VIEW triples AS SELECT
@@ -540,7 +540,7 @@
R_emp.lastName AS O
FROM Employee AS R_emp
""" // "
- val expected = View(RelName("triples"), Select(
+ val expected = View(RDB.RelName("triples"), Select(
false,
Projection(Set(
ProjectAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
@@ -548,17 +548,23 @@
PrimaryExpressionTyped(Datatype("String"),Name("/")),
PrimaryExpressionTyped(Datatype("String"),Name("empid")),
PrimaryExpressionTyped(Datatype("String"),Name(".")),
- PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),RDB.AttrName("id"))),
PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
AttrAlias(Name("S"))),
ProjectAttribute(PrimaryExpressionTyped(Datatype.STRING,Name("<http://hr.example/DB/Employee#lastName>")),
AttrAlias(Name("P"))),
ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
- AttrName("lastName")),
+ RDB.AttrName("lastName")),
AttrAlias(Name("O"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RDB.RelName("Employee"),RelVar(Name("R_emp"))), None))),
None, List[OrderElt](), None, None))
assert(expected === (a.parseAll(a.createview, e).get))
}
+ /**
+ * junk that should be elsewhere
+ */
+
+ implicit def relname2relresource (rn:RDB.RelName) : RelationResource = RelationResource(rn)
+
}