differentiated AttrAlias from Attribute and changed test names to include A_<alias>
authorEric Prud'hommeaux <bertails@w3.org>
Mon, 14 Dec 2009 14:15:03 -0500
changeset 33 63440246328f
parent 32 1e614afe9556
child 34 f289c47cb7fd
differentiated AttrAlias from Attribute and changed test names to include A_<alias>
src/main/scala/RDB2RDFMain.scala
src/main/scala/SQL.scala
src/test/scala/RDB2RDFTest.scala
src/test/scala/SQLTest.scala
--- a/src/main/scala/RDB2RDFMain.scala	Mon Dec 14 13:10:16 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala	Mon Dec 14 14:15:03 2009 -0500
@@ -19,10 +19,10 @@
 case class PrimaryKey(attr:Attribute)
 
 sealed abstract class Binding
-case class RDFNode(fqattr:AliasAttribute) extends Binding
-case class Str(fqattr:AliasAttribute) extends Binding
-case class Int(fqattr:AliasAttribute) extends Binding
-case class Enum(fqattr:AliasAttribute) extends Binding
+case class RDFNode(fqattr:RelAliasAttribute) extends Binding
+case class Str(fqattr:RelAliasAttribute) extends Binding
+case class Int(fqattr:RelAliasAttribute) extends Binding
+case class Enum(fqattr:RelAliasAttribute) extends Binding
 
 // case class NodeMap()
 // case class PredicateMap()
@@ -35,9 +35,9 @@
     bindings[VAR]= FQAttribute
 URIconstraint(URI) => Value:
     (Rel, Attr, Value) = match(URI, stemURI + '/' (\w+) '/' (\w+) '.' (\w+) '#record')
-    some Alias = hash(Rel + URI)
+    some RelAlias = hash(Rel + URI)
     pk = primary_key_attribute(Rel)
-    equivs.insert(Alias.pk= Value)
+    equivs.insert(RelAlias.pk= Value)
     joins.insert(Rel AS Attr)
     Value
 
@@ -46,55 +46,55 @@
 
 (rel, attr) = match(P, stemURI + '/' + (\w+) + '#' (\w+))
   * rel => Employee  attr => manager
-some alias = hash(Rel + S)
-  * alias => "emp"
+some relalias = hash(Rel + S)
+  * relalias => "emp"
 pk = primary_key_attribute(Rel)
   *-ignore, just use the paramater pk
     match S with
-      VAR -> VARconstraint(S, Alias.pk)
-  * eqS = (bindings[s => Alias.pk])
+      VAR -> VARconstraint(S, RelAlias.pk)
+  * eqS = (bindings[s => RelAlias.pk])
 XXX   URI -> URIconstraint(S)
     match O with
-      LITERAL -> equivs.insert(alias.attr= O)
-      VAR -> VARconstraint(O, Alias.Attr)
-      URI -> equivs.insert(Alias.Attr= URIconstraint(O))
+      LITERAL -> equivs.insert(relalias.attr= O)
+      VAR -> VARconstraint(O, RelAlias.Attr)
+      URI -> equivs.insert(RelAlias.Attr= URIconstraint(O))
       *
-  * joins.insert(RelAsAlias(rel, alias)
-joins.insert(rel AS alias ON eqS)
+  * joins.insert(RelAsRelAlias(rel, relalias)
+joins.insert(rel AS relalias ON eqS)
   * 
  * */
 object RDB2RDF {
-  case class R2RState(project:AttributeList, joins:List[Join], exprs:Expression, varmap:Map[Var, AliasAttribute])
+  case class R2RState(project:AttributeList, joins:List[Join], exprs:Expression, varmap:Map[Var, RelAliasAttribute])
 
-  def AliasFromS(s:S):Alias = {
+  def RelAliasFromS(s:S):RelAlias = {
     s match {
-      case SUri(ob) => AliasFromNode(ob)
-      case SVar(v) => AliasFromVar(v)
+      case SUri(ob) => RelAliasFromNode(ob)
+      case SVar(v) => RelAliasFromVar(v)
     }
   }
 
-  def AliasFromO(o:O):Option[Alias] = {
+  def RelAliasFromO(o:O):Option[RelAlias] = {
     o match {
-      case OUri(ob) => Some(AliasFromNode(ob))
-      case OVar(v) => Some(AliasFromVar(v))
+      case OUri(ob) => Some(RelAliasFromNode(ob))
+      case OVar(v) => Some(RelAliasFromVar(v))
       case OLit(l) => None
     }
   }
 
-  def AliasFromNode(u:ObjUri):Alias = {
+  def RelAliasFromNode(u:ObjUri):RelAlias = {
     val ObjUri(stem, rel, Attr(a), CellValue(v)) = u
-    Alias(Name(a + v))
+    RelAlias(Name(a + v))
   }
 
-  def AliasFromVar(vr:Var):Alias = {
+  def RelAliasFromVar(vr:Var):RelAlias = {
     val Var(v) = vr
-    Alias(Name("_" + v))
+    RelAlias(Name("R_" + v))
   }
 
   def URIconstraint(u:ObjUri, pk:PrimaryKey) = {
-    val alias = AliasFromNode(u)
+    val relalias = RelAliasFromNode(u)
     val ObjUri(stem, rel, attr, value) = u
-    val fqattr = AliasAttribute(alias, pk.attr)
+    val fqattr = RelAliasAttribute(relalias, pk.attr)
     println("equiv+= " + toString(fqattr) + "=" + value)
   }
 
@@ -103,7 +103,7 @@
    * passed the relation name (from predicate)
    *   if a subject, then the attribute is the primary key for relation
    *   if an object, then passed the attribute name (from predicate)
-   * passed the alias for this relation (e.g. _emp)
+   * passed the relalias for this relation (e.g. _emp)
    *
    * schema(Employee.id) => (?emp => NodeTemplate("Employee", _emp.id) stemURI + rel + fk(rel) + value
    * schema(Employee.lastName) => (?lastName => RValueString(_emp.lastName)
@@ -118,10 +118,10 @@
    * type String -> RDFStringConstructor // adds ^^xsd:string
    * type primary key -> RDFNodeConstructor // prefixes with stemURL + relation + attribute  and adds #record
    * */
-  def varConstraint(v:Var, db:DatabaseDesc, rel:Relation, alias:Alias, attr:Attribute) = {
-    /* e.g.                                 Employee      _emp 	          id            
-    **                                      Employee      _emp            lastName      
-    **                                      Employee      _emp            manager       
+  def varConstraint(v:Var, db:DatabaseDesc, rel:Relation, relalias:RelAlias, attr:Attribute) = {
+    /* e.g.                                 Employee      _emp 	             id            
+    **                                      Employee      _emp               lastName      
+    **                                      Employee      _emp               manager       
     */
     val reldesc = db.relationdescs(rel)
     val mapper:String = reldesc.primarykey match {
@@ -135,16 +135,16 @@
 	}
       }
     }
-    println("?" + v.s + "=> " + mapper + alias.n.s + "." + attr.n.s + ")")
+    println("?" + v.s + "=> " + mapper + relalias.n.s + "." + attr.n.s + ")")
     null
   }
 
-  def LiteralConstraint(lit:SparqlLiteral, attr:AliasAttribute) = {
+  def LiteralConstraint(lit:SparqlLiteral, attr:RelAliasAttribute) = {
     println("equiv+= " + toString(attr) + "=" + lit)
   }
 
-  def toString(fqattr:AliasAttribute) : String = {
-    fqattr.alias.n.s + "." + fqattr.attribute.n.s
+  def toString(fqattr:RelAliasAttribute) : String = {
+    fqattr.relalias.n.s + "." + fqattr.attribute.n.s
   }
   // def toString(fqattr:RelAttribute) : String = {
   //   "[" + fqattr.relation.n.s + "]" + fqattr.attribute.n.s
@@ -157,26 +157,26 @@
       case PUri(stem, spRel, spAttr) => {
 	val rel = Relation(Name(spRel.s))
 	val attr = Attribute(Name(spAttr.s))
-	val alias = AliasFromS(s)
-	println(rel.n.s + " AS " + alias.n.s)
+	val relalias = RelAliasFromS(s)
+	println(rel.n.s + " AS " + relalias.n.s)
 	s match {
 	  case SUri(u) => URIconstraint(u, pk)
-	  case SVar(v) => varConstraint(v, db, rel, alias, pk.attr)
+	  case SVar(v) => varConstraint(v, db, rel, relalias, pk.attr)
 	  null
 	}
-	val objattr = AliasAttribute(alias, attr)
+	val objattr = RelAliasAttribute(relalias, attr)
 	val target = db.relationdescs(rel).attributes(attr) match {
 	  case ForeignKey(fkrel, fkattr) => {
 	    o match {
 	      case OUri(u) => {
-		val oAlias = AliasFromNode(u)
-		println(toString(objattr) + "->" + toString(AliasAttribute(oAlias, fkattr)))
+		val oRelAlias = RelAliasFromNode(u)
+		println(toString(objattr) + "->" + toString(RelAliasAttribute(oRelAlias, fkattr)))
 		URIconstraint(u, pk)
 	      }
 	      case OVar(v) => {
-		val oAlias = AliasFromVar(v)
-		println(toString(objattr) + "->" + toString(AliasAttribute(oAlias, fkattr)))
-		varConstraint(v, db, fkrel, oAlias, fkattr)
+		val oRelAlias = RelAliasFromVar(v)
+		println(toString(objattr) + "->" + toString(RelAliasAttribute(oRelAlias, fkattr)))
+		varConstraint(v, db, fkrel, oRelAlias, fkattr)
 	      }
 	      case OLit(l) => LiteralConstraint(l, objattr)
 	    }
@@ -184,7 +184,7 @@
 	  case Value(dt) => {
 	    o match {
 	      case OUri(u) => URIconstraint(u, pk)
-	      case OVar(v) => varConstraint(v, db, rel, alias, attr)
+	      case OVar(v) => varConstraint(v, db, rel, relalias, attr)
 	      case OLit(l) => LiteralConstraint(l, objattr)
 	    }
 	  }
@@ -201,23 +201,23 @@
     var r2rState = R2RState(
       // AttributeList(List()), 
       AttributeList(List(
-	NamedAttribute(AliasAttribute(Alias(Name("emp")),Attribute(Name("lastName"))),Attribute(Name("empName"))), 
-	NamedAttribute(AliasAttribute(Alias(Name("manager")),Attribute(Name("lastName"))),Attribute(Name("managName"))))), 
+	NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName"))),AttrAlias(Name("A_empName"))), 
+	NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("lastName"))),AttrAlias(Name("A_managName"))))), 
       // List[Join](), 
       List(
-	Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("emp"))),None),
-	Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("manager"))),
+	Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None),
+	Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
 	     Some(Expression(List(
-	       PrimaryExpressionEq(AliasAttribute(Alias(Name("manager")),Attribute(Name("id"))),
-				   RValueAttr(AliasAttribute(Alias(Name("emp")),Attribute(Name("manager"))))))
+	       PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),
+				   RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("manager"))))))
 		      )))
       ), 
       // Expression(List()), 
       Expression(List(
-	PrimaryExpressionNotNull(AliasAttribute(Alias(Name("emp")),Attribute(Name("lastName")))), 
-	PrimaryExpressionNotNull(AliasAttribute(Alias(Name("manager")),Attribute(Name("lastName"))))
+	PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName")))), 
+	PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("lastName"))))
       )), 
-      Map[Var, AliasAttribute]()
+      Map[Var, RelAliasAttribute]()
     )
 
     triples.triplepatterns.foreach(s => r2rState = acc(db, r2rState, s, pk))
--- a/src/main/scala/SQL.scala	Mon Dec 14 13:10:16 2009 -0500
+++ b/src/main/scala/SQL.scala	Mon Dec 14 14:15:03 2009 -0500
@@ -7,22 +7,23 @@
 
 case class Select(attributelist:AttributeList, tablelist:TableList, expression:Option[Expression])
 case class AttributeList(attributes:List[NamedAttribute])
-case class NamedAttribute(fqattribute:AliasAttribute, attribute:Attribute)
+case class NamedAttribute(fqattribute:RelAliasAttribute, attralias:AttrAlias)
 //case class RelAttribute(relation:Relation, attribute:Attribute)
-case class AliasAttribute(alias:Alias, attribute:Attribute)
+case class RelAliasAttribute(relalias:RelAlias, attribute:Attribute)
 case class Attribute(n:Name)
+case class AttrAlias(n:Name)
 case class Relation(n:Name)
-case class Alias(n:Name)
+case class RelAlias(n:Name)
 case class TableList(joins:List[Join])
-case class Join(relasalias:RelAsAlias, expression:Option[Expression])
-case class RelAsAlias(rel:Relation, as:Alias)
+case class Join(relasalias:RelAsRelAlias, expression:Option[Expression])
+case class RelAsRelAlias(rel:Relation, as:RelAlias)
 case class Expression(conjuncts:List[PrimaryExpression])
 sealed abstract class PrimaryExpression
-case class PrimaryExpressionEq(l:AliasAttribute, r:RValue) extends PrimaryExpression
-case class PrimaryExpressionLt(l:AliasAttribute, r:RValue) extends PrimaryExpression
-case class PrimaryExpressionNotNull(l:AliasAttribute) extends PrimaryExpression
+case class PrimaryExpressionEq(l:RelAliasAttribute, r:RValue) extends PrimaryExpression
+case class PrimaryExpressionLt(l:RelAliasAttribute, r:RValue) extends PrimaryExpression
+case class PrimaryExpressionNotNull(l:RelAliasAttribute) extends PrimaryExpression
 sealed abstract class RValue
-case class RValueAttr(fqattribute:AliasAttribute) extends RValue
+case class RValueAttr(fqattribute:RelAliasAttribute) extends RValue
 case class RValueTyped(datatype:SQLDatatype, i:Name) extends RValue
 case class Name(s:String)
 
@@ -58,22 +59,25 @@
     repsep(namedattribute, ",") ^^ { AttributeList(_) }
 
   def namedattribute:Parser[NamedAttribute] =
-    fqattribute ~ "AS" ~ attribute ^^
-    { case fqattribute ~ "AS" ~ attribute =>
-      NamedAttribute(fqattribute, attribute) }
+    fqattribute ~ "AS" ~ attralias ^^
+    { case fqattribute ~ "AS" ~ attralias =>
+      NamedAttribute(fqattribute, attralias) }
 
-  def fqattribute:Parser[AliasAttribute] =
-    alias ~ "." ~ attribute ^^
-    { case alias ~ "." ~ attribute => AliasAttribute(alias, attribute) }
+  def fqattribute:Parser[RelAliasAttribute] =
+    relalias ~ "." ~ attribute ^^
+    { case relalias ~ "." ~ attribute => RelAliasAttribute(relalias, attribute) }
 
   def attribute:Parser[Attribute] =
     """[a-zA-Z_]\w*""".r ^^ { x => Attribute(Name(x)) }
 
+  def attralias:Parser[AttrAlias] =
+    """[a-zA-Z_]\w*""".r ^^ { x => AttrAlias(Name(x)) }
+
   def relation:Parser[Relation] =
     """[a-zA-Z_]\w*""".r ^^ { x => Relation(Name(x)) }
 
-  def alias:Parser[Alias] =
-    """[a-zA-Z_]\w*""".r ^^ { x => Alias(Name(x)) }
+  def relalias:Parser[RelAlias] =
+    """[a-zA-Z_]\w*""".r ^^ { x => RelAlias(Name(x)) }
 
   def tablelist:Parser[TableList] =
     repsep(join, "INNER" ~ "JOIN") ^^ { TableList(_) }
@@ -85,9 +89,9 @@
   def optexpr:Parser[Expression] =
     "ON" ~ expression ^^ { case "ON"~expression => expression }
 
-  def relasalias:Parser[RelAsAlias] =
-    relation ~ "AS" ~ alias ^^
-    { case rel1 ~ "AS" ~ rel2 => RelAsAlias(rel1, rel2) }
+  def relasalias:Parser[RelAsRelAlias] =
+    relation ~ "AS" ~ relalias ^^
+    { case rel1 ~ "AS" ~ rel2 => RelAsRelAlias(rel1, rel2) }
 
   def expression:Parser[Expression] = 
     repsep(primaryexpression, "AND") ^^ 
--- a/src/test/scala/RDB2RDFTest.scala	Mon Dec 14 13:10:16 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala	Mon Dec 14 14:15:03 2009 -0500
@@ -15,7 +15,7 @@
 			 Attribute("address") -> ForeignKey(Relation("Address"),  Attribute("id"))))))
 
 
-  test("SQLbgp") {
+  test("transform SQLbgp") {
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
 SELECT ?empName ?manageName {
@@ -27,10 +27,10 @@
 """).get
     val sqlParser = Sql()
     val sqlSelect = sqlParser.parseAll(sqlParser.select, """
-SELECT emp.lastName AS empName, manager.lastName AS managName
-       FROM Employee AS emp
-            INNER JOIN Employee AS manager ON manager.id=emp.manager
- WHERE emp.lastName IS NOT NULL AND manager.lastName IS NOT NULL
+SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_managName
+       FROM Employee AS R_emp
+            INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
+ WHERE R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
 """).get
     assert(RDB2RDF(db, sparqlSelect, StemURI("http://hr.example/DB/"), PrimaryKey(Attribute(Name("id")))) === sqlSelect)
   }
--- a/src/test/scala/SQLTest.scala	Mon Dec 14 13:10:16 2009 -0500
+++ b/src/test/scala/SQLTest.scala	Mon Dec 14 14:15:03 2009 -0500
@@ -5,111 +5,111 @@
 
 class SQLTest extends FunSuite {
 
-  test("SQLbgp") {
+  test("parse SQLbgp") {
     val a = Sql()
     val e = """
-SELECT emp.lastName AS empName, manager.lastName AS managName
-       FROM Employee AS emp
-            INNER JOIN Employee AS manager ON manager.id=emp.manager
- WHERE emp.lastName IS NOT NULL AND manager.lastName IS NOT NULL
+SELECT R_emp.lastName AS A_empName, R_manager.lastName AS A_managName
+       FROM Employee AS R_emp
+            INNER JOIN Employee AS R_manager ON R_manager.id=R_emp.manager
+ WHERE R_emp.lastName IS NOT NULL AND R_manager.lastName IS NOT NULL
 """
-    val expected = Select(AttributeList(List(NamedAttribute(AliasAttribute(Alias(Name("emp")),
-									Attribute(Name("lastName"))),
-							    Attribute(Name("empName"))),
-					     NamedAttribute(AliasAttribute(Alias(Name("manager")),
-									Attribute(Name("lastName"))),
-							    Attribute(Name("managName"))))),
-			  TableList(List(Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("emp"))),None),
-					 Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("manager"))),
-					      Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("manager")),
-												   Attribute(Name("id"))),
-										       RValueAttr(AliasAttribute(Alias(Name("emp")),
-													      Attribute(Name("manager"))))))))))),
-			  Some(Expression(List(PrimaryExpressionNotNull(AliasAttribute(Alias(Name("emp")),
-										    Attribute(Name("lastName")))),
-					       PrimaryExpressionNotNull(AliasAttribute(Alias(Name("manager")),
-										    Attribute(Name("lastName"))))))))
-    assert(expected === (a.parseAll(a.select, e).get))
-  }
-
-  test("tup1") {
-    val a = Sql()
-    val e = """
-SELECT emp.lastName AS empName
-  FROM Employee AS emp
- WHERE emp.manager=18 AND emp.lastName IS NOT NULL
-"""
-    val expected = Select(AttributeList(List(NamedAttribute(AliasAttribute(Alias(Name("emp")),
-									Attribute(Name("lastName"))),
-							    Attribute(Name("empName"))))),
-			  TableList(List(Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("emp"))),None))),
-			  Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("emp")),
-									       Attribute(Name("manager"))),
-								   RValueTyped(SQLDatatype.INTEGER,Name("18"))),
-					       PrimaryExpressionNotNull(AliasAttribute(Alias(Name("emp")),
-										    Attribute(Name("lastName"))))))))
+    val expected = Select(AttributeList(List(NamedAttribute(RelAliasAttribute(RelAlias(Name("R_emp")),
+									      Attribute(Name("lastName"))),
+							    AttrAlias(Name("A_empName"))),
+					     NamedAttribute(RelAliasAttribute(RelAlias(Name("R_manager")),
+									      Attribute(Name("lastName"))),
+							    AttrAlias(Name("A_managName"))))),
+			  TableList(List(Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_emp"))),None),
+					 Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
+					      Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),
+													 Attribute(Name("id"))),
+										       RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),
+														    Attribute(Name("manager"))))))))))),
+			  Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
+											  Attribute(Name("lastName")))),
+					       PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_manager")),
+											  Attribute(Name("lastName"))))))))
     assert(expected === (a.parseAll(a.select, e).get))
   }
 
-  test("litConst1") {
+  test("parse tup1") {
     val a = Sql()
     val e = """
-SELECT emp.lastName AS empName
-  FROM Employee AS emp
-       INNER JOIN Employee AS manager ON emp.manager=manager.id
-                                       AND manager.lastName="Johnson"
-WHERE emp.lastName IS NOT NULL
+SELECT R_emp.lastName AS A_empName
+  FROM Employee AS R_emp
+ WHERE R_emp.manager=18 AND R_emp.lastName IS NOT NULL
 """
-    val expected = Select(AttributeList(List(NamedAttribute(AliasAttribute(Alias(Name("emp")),
-									Attribute(Name("lastName"))),
-							    Attribute(Name("empName"))))),
-			  TableList(List(Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("emp"))),None),
-					 Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("manager"))),
-					      Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("emp")),
-												   Attribute(Name("manager"))),
-										       RValueAttr(AliasAttribute(Alias(Name("manager")),
-													      Attribute(Name("id"))))),
-								   PrimaryExpressionEq(AliasAttribute(Alias(Name("manager")),
-												   Attribute(Name("lastName"))),
-										       RValueTyped(SQLDatatype.STRING,Name("Johnson"))))))))),
-			  Some(Expression(List(PrimaryExpressionNotNull(AliasAttribute(Alias(Name("emp")),Attribute(Name("lastName"))))))))
+    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"))),None))),
+			  Some(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"))))))))
     assert(expected === (a.parseAll(a.select, e).get))
   }
 
-  test("filter1") {
+  test("parse litConst1") {
     val a = Sql()
     val e = """
-SELECT emp.lastName AS empName, grandManager.lastName AS grandManagName
-  FROM Employee AS emp
-       INNER JOIN Manage AS lower ON lower.manages=emp.id
-       INNER JOIN Employee AS manager ON manager.id=lower.manager
-                                         AND manager.birthday < emp.birthday
-       INNER JOIN Manage AS upper ON upper.manages=manager.id
-       INNER JOIN Employee AS grandManager ON grandManager.id=upper.manager
-                                         AND grandManager.birthday < manager.birthday
- WHERE emp.lastName IS NOT NULL AND grandManager.lastName IS NOT NULL
+SELECT R_emp.lastName AS A_empName
+  FROM Employee AS R_emp
+       INNER JOIN Employee AS R_manager ON R_emp.manager=R_manager.id
+                                       AND R_manager.lastName="Johnson"
+WHERE R_emp.lastName IS NOT NULL
 """
-    val expected = Select(AttributeList(List(NamedAttribute(AliasAttribute(Alias(Name("emp")), Attribute(Name("lastName"))),
-							    Attribute(Name("empName"))),
-					     NamedAttribute(AliasAttribute(Alias(Name("grandManager")),Attribute(Name("lastName"))),
-							    Attribute(Name("grandManagName"))))),
-			  TableList(List(Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("emp"))),None),
-					 Join(RelAsAlias(Relation(Name("Manage")),Alias(Name("lower"))),Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("lower")),Attribute(Name("manages"))),RValueAttr(AliasAttribute(Alias(Name("emp")),Attribute(Name("id"))))))))),
-					 Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("manager"))),Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("manager")),Attribute(Name("id"))),RValueAttr(AliasAttribute(Alias(Name("lower")),Attribute(Name("manager"))))), PrimaryExpressionLt(AliasAttribute(Alias(Name("manager")),Attribute(Name("birthday"))),RValueAttr(AliasAttribute(Alias(Name("emp")),Attribute(Name("birthday"))))))))),
-					 Join(RelAsAlias(Relation(Name("Manage")),Alias(Name("upper"))),Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("upper")),Attribute(Name("manages"))),RValueAttr(AliasAttribute(Alias(Name("manager")),Attribute(Name("id"))))))))),
-					 Join(RelAsAlias(Relation(Name("Employee")),Alias(Name("grandManager"))),
-					      Some(Expression(List(PrimaryExpressionEq(AliasAttribute(Alias(Name("grandManager")),
-												      Attribute(Name("id"))),
-										       RValueAttr(AliasAttribute(Alias(Name("upper")),
-														 Attribute(Name("manager"))))),
-								   PrimaryExpressionLt(AliasAttribute(Alias(Name("grandManager")),
-												      Attribute(Name("birthday"))),
-										       RValueAttr(AliasAttribute(Alias(Name("manager")),
-														 Attribute(Name("birthday"))))))))))),
-			  Some(Expression(List(PrimaryExpressionNotNull(AliasAttribute(Alias(Name("emp")),
-										       Attribute(Name("lastName")))),
-					       PrimaryExpressionNotNull(AliasAttribute(Alias(Name("grandManager")),
-										       Attribute(Name("lastName"))))))))
+    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"))),None),
+					 Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),
+					      Some(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"))),
+										       RValueTyped(SQLDatatype.STRING,Name("Johnson"))))))))),
+			  Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("lastName"))))))))
+    assert(expected === (a.parseAll(a.select, e).get))
+  }
+
+  test("parse filter1") {
+    val a = Sql()
+    val e = """
+SELECT R_emp.lastName AS A_empName, R_grandManager.lastName AS A_grandManagName
+  FROM Employee AS R_emp
+       INNER JOIN Manage AS R_lower ON R_lower.manages=R_emp.id
+       INNER JOIN Employee AS R_manager ON R_manager.id=R_lower.R_manager
+                                         AND R_manager.birthday < R_emp.birthday
+       INNER JOIN Manage AS R_upper ON R_upper.manages=R_manager.id
+       INNER JOIN Employee AS R_grandManager ON R_grandManager.id=R_upper.R_manager
+                                         AND R_grandManager.birthday < R_manager.birthday
+ WHERE 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"))),
+							    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"))),None),
+					 Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_lower"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("id"))))))))),
+					 Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_manager"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_lower")),Attribute(Name("R_manager"))))), PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("birthday"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_emp")),Attribute(Name("birthday"))))))))),
+					 Join(RelAsRelAlias(Relation(Name("Manage")),RelAlias(Name("R_upper"))),Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_upper")),Attribute(Name("manages"))),RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),Attribute(Name("id"))))))))),
+					 Join(RelAsRelAlias(Relation(Name("Employee")),RelAlias(Name("R_grandManager"))),
+					      Some(Expression(List(PrimaryExpressionEq(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+													 Attribute(Name("id"))),
+										       RValueAttr(RelAliasAttribute(RelAlias(Name("R_upper")),
+														    Attribute(Name("R_manager"))))),
+								   PrimaryExpressionLt(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+													 Attribute(Name("birthday"))),
+										       RValueAttr(RelAliasAttribute(RelAlias(Name("R_manager")),
+														    Attribute(Name("birthday"))))))))))),
+			  Some(Expression(List(PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_emp")),
+											  Attribute(Name("lastName")))),
+					       PrimaryExpressionNotNull(RelAliasAttribute(RelAlias(Name("R_grandManager")),
+											  Attribute(Name("lastName"))))))))
     assert(expected === (a.parseAll(a.select, e).get))
   }