--- a/src/main/scala/RDB2RDFMain.scala Wed Dec 16 17:08:03 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Wed Dec 16 17:23:24 2009 -0500
@@ -13,7 +13,7 @@
case class Enum(relaliasattr:RelAliasAttribute) extends Binding
object RDB2RDF {
- case class R2RState(joined:Set[RelAlias], allVars:List[Var], inConstraint:Set[Var], joins:List[Join], varmap:Map[Var, SQL2RDFValueMapper], exprs:List[PrimaryExpression])
+ case class R2RState(joined:Set[RelAlias], allVars:List[Var], inConstraint:Set[Var], joins:List[AliasedResource], varmap:Map[Var, SQL2RDFValueMapper], exprs:List[PrimaryExpression])
sealed abstract class SQL2RDFValueMapper(relaliasattr:RelAliasAttribute)
case class StringMapper(relaliasattr:RelAliasAttribute) extends SQL2RDFValueMapper(relaliasattr)
@@ -137,9 +137,9 @@
}
val sjoin = joined contains(relalias) match {
case false => {
- //joins = joins ::: List(Join(RelAsRelAlias(rel,relalias), sconstraint))
+ //joins = joins ::: List(Join(AliasedResource(rel,relalias), sconstraint))
joined = joined + relalias
- Some(RelAsRelAlias(rel,relalias))
+ Some(AliasedResource(rel,relalias))
}
case true => None
}
@@ -174,19 +174,19 @@
case false => {
sjoin match { // complex dance to keep joins ordered -- ouch!
- case Some(x) => joins = joins ::: List(Join(x))
+ case Some(x) => joins = joins ::: List(x)
case None =>
}
exprs = exprs ::: conjuncts
- joins = joins ::: List(Join(RelAsRelAlias(fkrel,oRelAlias)))
+ joins = joins ::: List(AliasedResource(fkrel,oRelAlias))
joined = joined + oRelAlias
}
case true => {
sjoin match {
case Some(x) => {
exprs = exprs ::: conjuncts
- joins = joins ::: List(Join(x))
+ joins = joins ::: List(x)
}
case None =>
}
@@ -208,7 +208,7 @@
}
}
sjoin match {
- case Some(x) => joins = joins ::: List(Join(x))
+ case Some(x) => joins = joins ::: List(x)
case None =>
}
@@ -286,7 +286,7 @@
Set[RelAlias](),
List[Var](),
Set[Var](),
- List[Join](),
+ List[AliasedResource](),
Map[Var, SQL2RDFValueMapper](),
List[PrimaryExpression]()
)
--- a/src/main/scala/SQL.scala Wed Dec 16 17:08:03 2009 -0500
+++ b/src/main/scala/SQL.scala Wed Dec 16 17:23:24 2009 -0500
@@ -12,9 +12,8 @@
case class AttrAlias(n:Name)
case class Relation(n:Name)
case class RelAlias(n:Name)
-case class TableList(joins:List[Join])
-case class Join(relasalias:RelAsRelAlias)
-case class RelAsRelAlias(rel:Relation, as:RelAlias)
+case class TableList(joins:List[AliasedResource])
+case class AliasedResource(rel:Relation, as:RelAlias)
case class Expression(conjuncts:List[PrimaryExpression])
sealed abstract class PrimaryExpression
case class PrimaryExpressionEq(l:RelAliasAttribute, r:RValue) extends PrimaryExpression
@@ -85,14 +84,11 @@
"""[a-zA-Z_]\w*""".r ^^ { x => RelAlias(Name(x)) }
def tablelist:Parser[TableList] =
- repsep(join, "INNER" ~ "JOIN") ^^ { TableList(_) }
+ repsep(aliasedjoin, "INNER" ~ "JOIN") ^^ { TableList(_) }
- def join:Parser[Join] =
- relasalias ^^ { x => Join(x) }
-
- def relasalias:Parser[RelAsRelAlias] =
+ def aliasedjoin:Parser[AliasedResource] =
relation ~ "AS" ~ relalias ^^
- { case rel1 ~ "AS" ~ rel2 => RelAsRelAlias(rel1, rel2) }
+ { case rel1 ~ "AS" ~ rel2 => AliasedResource(rel1, rel2) }
def expression:Parser[Expression] =
repsep(primaryexpression, "AND") ^^
--- a/src/test/scala/SQLTest.scala Wed Dec 16 17:08:03 2009 -0500
+++ b/src/test/scala/SQLTest.scala Wed Dec 16 17:23:24 2009 -0500
@@ -19,8 +19,8 @@
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_managName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager")))))),
+ TableList(List(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))),
+ AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_manager"))))),
Expression(List(
PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),
RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("manager"))))),
@@ -39,7 +39,7 @@
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))))),
+ TableList(List(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))))),
Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("manager"))),
RValueTyped(SQLDatatype.INTEGER,Name("18"))),
PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName")))))))
@@ -57,8 +57,8 @@
val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager")))))),
+ TableList(List(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))),
+ AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_manager"))))),
Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("manager"))),
RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))))),
PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("lastName"))),
@@ -86,11 +86,11 @@
AttrAlias(Name("A_empName"))),
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_grandManager")),Attribute(Name("lastName"))),
AttrAlias(Name("A_grandManagName"))))),
- TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp")))),
- Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_lower")))),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager")))),
- Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_upper")))),
- Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_grandManager")))))),
+ TableList(List(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))),
+ AliasedResource(Relation(Name("Manage")),RelAlias(Name("R_lower"))),
+ AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
+ AliasedResource(Relation(Name("Manage")),RelAlias(Name("R_upper"))),
+ AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_grandManager"))))),
Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manages"))),
RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("id"))))),
PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),