--- a/src/test/scala/SQLTest.scala Fri Oct 08 15:58:19 2010 -0400
+++ b/src/test/scala/SQLTest.scala Wed Oct 13 23:21:16 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")),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")))))))
+ 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"))))))
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")),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")))))))
+ 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"))))))
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")),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")))))))
+ 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"))))))
assert(expected === (a.parseAll(a.expression, e).get))
}
@@ -56,7 +56,7 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(PrimaryExpressionTyped(Datatype.INTEGER,Name("1")),
+ Projection(Set(ProjectAttribute(PrimaryExpressionTyped(Datatype.INTEGER,Name("1")),
AttrAlias(Name("_TEST_"))))),
TableList(AddOrderedSet()),
None, List[OrderElt](), None, None)
@@ -74,20 +74,20 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("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))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RelName("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")))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
test("parse INNER JOIN ON") {
- // AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp")))
+ // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
SELECT R_emp.lastName AS A_empName
@@ -96,20 +96,20 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("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))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None),
+ InnerJoin(AliasedResource(RelName("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")))))),
+ RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_manager")),AttrName("id"))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
test("parse SQLbgp") {
- // AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp")))
+ // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_managName
@@ -119,19 +119,19 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("lastName")),
AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_manager")),
- Attribute(Name("lastName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_manager")),
+ AttrName("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))),
+ 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_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")))))))),
+ 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"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -145,13 +145,13 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("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")))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
+ Some(ExprConjunction(Set(RelationalExpressionEq(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("manager"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("18"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -166,16 +166,16 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("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")))),
+ 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"))),
PrimaryExpressionTyped(Datatype.STRING,Name("Johnson"))),
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -197,29 +197,29 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")), Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")), AttrName("lastName")),
AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_grandManager")),Attribute(Name("lastName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_grandManager")),AttrName("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")))))))),
+ 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"))))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -244,42 +244,42 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_union1")), Attribute(Name("name"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_union1")), AttrName("name")),
AttrAlias(Name("A_name"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_who"))), None),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_who"))), None),
InnerJoin(AliasedResource(Subselect(Union(Set(
Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_manager")), Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_manager")), AttrName("lastName")),
AttrAlias(Name("A_name"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_above")), Attribute(Name("manages"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_above")), AttrName("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)
+ InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None),
+ InnerJoin(AliasedResource(RelName("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")))))))),
+ 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"))))))),
List[OrderElt](), None, None),
Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_managed")), Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_managed")), AttrName("lastName")),
AttrAlias(Name("A_name"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_below")), Attribute(Name("manager"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_below")), AttrName("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)
+ InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_below"))), None),
+ InnerJoin(AliasedResource(RelName("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")))))))),
+ 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"))))))),
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")))),
+ 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"))),
PrimaryExpressionTyped(Datatype.STRING,Name("Smith")))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
@@ -294,14 +294,14 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
- Attribute(Name("manages"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_above")),
+ AttrName("manages")),
AttrAlias(Name("A_who"))),
- NamedAttribute(ConstNULL(),
+ ProjectAttribute(ConstNULL(),
AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None))),
Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))))),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -314,15 +314,15 @@
FROM Employee AS R_emp
"""
val expected = Select(
- false, AttributeList(Set(NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
+ false, Projection(Set(ProjectAttribute(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")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id"))),
PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
AttrAlias(Name("A_emp"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
None, List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
}
@@ -336,19 +336,19 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_above")),
- Attribute(Name("manages"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_above")),
+ AttrName("manages")),
AttrAlias(Name("A_who"))),
- NamedAttribute(ConstNULL(),
+ ProjectAttribute(ConstNULL(),
AttrAlias(Name("A_bday"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Manage")),RelVar(Name("R_above"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Manage"),RelVar(Name("R_above"))), None))),
Some(
ExprDisjunction(Set(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id"))))),
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id")))),
ExprConjunction(Set(
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("5"))),
- RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),Attribute(Name("id")))),
+ RelationalExpressionLt(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_above")),AttrName("id"))),
PrimaryExpressionTyped(Datatype.INTEGER,Name("3")))
))))),
List[OrderElt](), None, None)
@@ -365,19 +365,19 @@
"""
val expected = Select(
false,
- AttributeList(Set(NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ Projection(Set(ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("lastName")),
AttrAlias(Name("A_empName"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_mang")),
- Attribute(Name("manageName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_mang")),
+ AttrName("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"))))
+ 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")))
)))),
Some(
- RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),Attribute(Name("lastName")))))
+ RelationalExpressionNotNull(PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("lastName"))))
),
List[OrderElt](), None, None)
assert(expected === (a.parseAll(a.select, e).get))
@@ -397,20 +397,20 @@
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),
+ 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),
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))),
+ 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))),
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")))))),
+ 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"))))),
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(Attribute("ID"), Value(Datatype.INTEGER), true)
+ val expected = FieldDesc(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 =
- (Relation("Sex_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER))))
+ (RelName("Sex_DE") ->
+ RelationDesc(Option(AttrName("ID")),
+ Map(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(Relation("Sex_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
+ Map(RelName("Sex_DE") ->
+ RelationDesc(Option(AttrName("ID")),
+ Map(AttrName("ID") -> Value(Datatype.INTEGER),
+ 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(Relation("Sex_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("EnterpriseEntryID") -> Value(Datatype.INTEGER)))))
+ Map(RelName("Sex_DE") ->
+ RelationDesc(Option(AttrName("ID")),
+ Map(AttrName("ID") -> Value(Datatype.INTEGER),
+ 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(Relation("Person") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("MiddleName") -> Value(Datatype.STRING),
- Attribute("DateOfBirth") -> Value(Datatype.DATE),
- Attribute("SexDE") -> ForeignKey(Relation("Sex_DE"), Attribute("ID")))),
- Relation("Sex_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("EntryName") -> Value(Datatype.STRING)))
+ 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)))
))
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(Relation("Person") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("MiddleName") -> Value(Datatype.STRING),
- Attribute("DateOfBirth") -> Value(Datatype.DATE),
- Attribute("SexDE") -> ForeignKey(Relation("Sex_DE"), Attribute("ID")))),
- Relation("Sex_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("EntryName") -> Value(Datatype.STRING))),
- Relation("Item_Medication") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("PatientID") -> ForeignKey(Relation("Person"), Attribute("ID")),
- Attribute("PerformedDTTM") -> Value(Datatype.DATE),
- Attribute("EntryName") -> Value(Datatype.STRING))),
- Relation("Medication") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("ItemID") -> ForeignKey(Relation("Item_Medication"), Attribute("ID")),
- Attribute("MedDictDE") -> ForeignKey(Relation("Medication_DE"), Attribute("ID")))),
- Relation("Medication_DE") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("NDC") -> Value(Datatype.INTEGER))),
- Relation("NDCcodes") ->
- RelationDesc(Option(Attribute("ID")),
- Map(Attribute("ID") -> Value(Datatype.INTEGER),
- Attribute("NDC") -> Value(Datatype.INTEGER),
- Attribute("ingredient") -> Value(Datatype.INTEGER)))
+ 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)))
))
assert(expected === (a.parseAll(a.ddl, e).get))
}
test("CREATE VIEW") {
- // AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp")))
+ // AliasedResource(RelName("Employee"),RelVar(Name("R_emp")))
val a = Sql()
val e = """
CREATE VIEW triples AS SELECT
@@ -540,23 +540,23 @@
R_emp.lastName AS O
FROM Employee AS R_emp
""" // "
- val expected = View(Relation(Name("triples")), Select(
+ val expected = View(RelName("triples"), Select(
false,
- AttributeList(Set(
- NamedAttribute(Concat(List(PrimaryExpressionTyped(Datatype("String"),Name("http://hr.example/DB/")),
+ Projection(Set(
+ ProjectAttribute(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")))),
+ PrimaryExpressionAttr(RelVarAttr(RelVar(Name("R_emp")),AttrName("id"))),
PrimaryExpressionTyped(Datatype("String"),Name("#record")))),
AttrAlias(Name("S"))),
- NamedAttribute(PrimaryExpressionTyped(Datatype.STRING,Name("<http://hr.example/DB/Employee#lastName>")),
+ ProjectAttribute(PrimaryExpressionTyped(Datatype.STRING,Name("<http://hr.example/DB/Employee#lastName>")),
AttrAlias(Name("P"))),
- NamedAttribute(RelVarAttr(RelVar(Name("R_emp")),
- Attribute(Name("lastName"))),
+ ProjectAttribute(RelVarAttr(RelVar(Name("R_emp")),
+ AttrName("lastName")),
AttrAlias(Name("O"))))),
- TableList(AddOrderedSet(InnerJoin(AliasedResource(Relation(Name("Employee")),RelVar(Name("R_emp"))), None))),
+ TableList(AddOrderedSet(InnerJoin(AliasedResource(RelName("Employee"),RelVar(Name("R_emp"))), None))),
None, List[OrderElt](), None, None))
assert(expected === (a.parseAll(a.createview, e).get))
}