--- a/src/main/scala/RDB2RDFMain.scala Wed Dec 16 19:19:15 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala Wed Dec 16 19:26:42 2009 -0500
@@ -13,7 +13,7 @@
case class Enum(relaliasattr:RelAliasAttribute) extends Binding
object RDB2RDF {
- case class R2RState(allVars:List[Var], inConstraint:Set[Var], joins:Set[AliasedResource], varmap:Map[Var, SQL2RDFValueMapper], exprs:Set[PrimaryExpression])
+ case class R2RState(allVars:Set[Var], inConstraint:Set[Var], joins:Set[AliasedResource], varmap:Map[Var, SQL2RDFValueMapper], exprs:Set[PrimaryExpression])
sealed abstract class SQL2RDFValueMapper(relaliasattr:RelAliasAttribute)
case class StringMapper(relaliasattr:RelAliasAttribute) extends SQL2RDFValueMapper(relaliasattr)
@@ -164,7 +164,7 @@
case OLit(l) => exprs += literalConstraint(objattr, l, dt)
case OUri(u) => exprs += uriConstraint(objattr, u)
case OVar(v) => {
- allVars = allVars ::: List(v)
+ allVars += v
// !! 2nd+ ref implies constraint
val binding = varConstraint(objattr, v, db, rel)
varmap += v -> binding
@@ -240,7 +240,7 @@
/* Create an object to hold our compilation state. */
var r2rState = R2RState(
- List[Var](),
+ Set[Var](),
Set[Var](),
Set[AliasedResource](),
Map[Var, SQL2RDFValueMapper](),
@@ -252,10 +252,10 @@
/* Select the attributes corresponding to the variables
* in the SPARQL SELECT. */
- var attrlist:List[NamedAttribute] = List()
- attrs.attributelist.foreach(vvar => attrlist = attrlist ::: List(
+ var attrlist:Set[NamedAttribute] = Set()
+ attrs.attributelist.foreach(vvar => attrlist +=
NamedAttribute(varToAttribute(r2rState.varmap, vvar), AttrAlias(Name("A_" + vvar.s)))
- ))
+ )
var exprs:Set[PrimaryExpression] = r2rState.exprs
var inConstraint:Set[Var] = r2rState.inConstraint
--- a/src/main/scala/SQL.scala Wed Dec 16 19:19:15 2009 -0500
+++ b/src/main/scala/SQL.scala Wed Dec 16 19:26:42 2009 -0500
@@ -4,7 +4,7 @@
import java.net.URI
case class Select(attributelist:AttributeList, tablelist:TableList, expression:Expression)
-case class AttributeList(attributes:List[NamedAttribute])
+case class AttributeList(attributes:Set[NamedAttribute])
case class NamedAttribute(fqattribute:RelAliasAttribute, attralias:AttrAlias)
//case class RelAttribute(relation:Relation, attribute:Attribute) c.f. ForeignKey
case class RelAliasAttribute(relalias:RelAlias, attribute:Attribute)
@@ -60,7 +60,7 @@
"WHERE" ~ expression ^^ { case "WHERE" ~ expression => expression }
def attributelist:Parser[AttributeList] =
- repsep(namedattribute, ",") ^^ { AttributeList(_) }
+ repsep(namedattribute, ",") ^^ { l => AttributeList(l.toSet) }
def namedattribute:Parser[NamedAttribute] =
fqattribute ~ "AS" ~ attralias ^^
--- a/src/test/scala/SQLTest.scala Wed Dec 16 19:19:15 2009 -0500
+++ b/src/test/scala/SQLTest.scala Wed Dec 16 19:26:42 2009 -0500
@@ -13,7 +13,7 @@
INNER JOIN Employee AS R_manager
WHERE R_manager.id=R_emp.manager AND R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
+ val expected = Select(AttributeList(Set(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))),
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),
@@ -36,7 +36,7 @@
FROM Employee AS R_emp
WHERE R_emp.manager=18 AND R_emp.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
+ val expected = Select(AttributeList(Set(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
TableList(Set(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))))),
@@ -54,7 +54,7 @@
INNER JOIN Employee AS R_manager
WHERE R_emp.manager=R_manager.id AND R_manager.lastName="Johnson" AND R_emp.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
+ val expected = Select(AttributeList(Set(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))))),
TableList(Set(AliasedResource(Relation(Name("Employee")),RelAlias(Name("R_emp"))),
@@ -82,7 +82,7 @@
AND R_grandManager.birthday < R_manager.birthday
AND R_emp.lastName IS NOT NULL AND R_grandManager.lastName IS NOT NULL
"""
- val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")), Attribute(Name("lastName"))),
+ val expected = Select(AttributeList(Set(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")), Attribute(Name("lastName"))),
AttrAlias(Name("A_empName"))),
NamedAttribute(RelAliasAttribute(RelAlias(Name("R_grandManager")),Attribute(Name("lastName"))),
AttrAlias(Name("A_grandManagName"))))),