~ use DDL instead of scala constructs
authorEric Prud'hommeaux <eric@w3.org>
Sat, 27 Feb 2010 00:26:57 -0500
changeset 175 2d389929e595
parent 174 1c281daa6a8b
child 176 afb41e675eaf
~ use DDL instead of scala constructs
src/test/scala/SparqlToSqlTest.scala
--- a/src/test/scala/SparqlToSqlTest.scala	Fri Feb 26 19:17:02 2010 -0500
+++ b/src/test/scala/SparqlToSqlTest.scala	Sat Feb 27 00:26:57 2010 -0500
@@ -37,23 +37,13 @@
        +--------+--------+------+
  */
 
-  val db:DatabaseDesc = DatabaseDesc(
-    Map(Relation("Employee") -> 
-	RelationDesc(Option(Attribute("empid")), 
-		     Map(Attribute("empid") -> Value(Datatype.INTEGER),
-			 Attribute("lastName") -> Value(Datatype.STRING),
-			 Attribute("birthday") -> Value(Datatype.DATE),
-			 Attribute("manager") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
-	Relation("Tasks") -> 
-	RelationDesc(Option(Attribute("taskid")),
-		     Map(Attribute("taskid") -> Value(Datatype.INTEGER),
-			 Attribute("name") -> Value(Datatype.STRING),
-			 Attribute("lead") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
-	Relation("TaskAssignments") -> 
-	RelationDesc(Option(Attribute("id")),
-		     Map(Attribute("task") -> ForeignKey(Relation("Tasks"), Attribute("taskid")), 
-			 Attribute("employee") -> ForeignKey(Relation("Employee"),  Attribute("empid"))))
-      ))
+  val DDLParser = Sql()
+  val dbDdl = """
+CREATE TABLE Employee (empid INT, PRIMARY KEY (empid), lastName STRING, birthday DATE, manager INT, FOREIGN KEY (manager) REFERENCES Employee(empid));
+CREATE TABLE Tasks (taskid INT, PRIMARY KEY (taskid), name STRING, lead INT, FOREIGN KEY (lead) REFERENCES Employee(empid));
+CREATE TABLE TaskAssignments (id INT PRIMARY KEY, PRIMARY KEY (id), task INT, FOREIGN KEY (task) REFERENCES Tasks(taskid), employee INT, FOREIGN KEY (employee) REFERENCES Employee(empid));
+"""
+  val db:DatabaseDesc = DDLParser.parseAll(DDLParser.ddl, dbDdl).get
 
 /* The reference RDF representation (queriable with the SPARQL in the tests) is:
  */
@@ -846,38 +836,15 @@
 """
   }
 
-  val hosp1: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)))
-      ))
+  val hosp1Ddl = """
+CREATE TABLE Person (ID INT PRIMARY KEY, MiddleName STRING, DateOfBirth DATE, SexDE INT, PRIMARY KEY (ID), FOREIGN KEY (SexDE) REFERENCES Sex_DE(ID));
+CREATE TABLE Sex_DE (ID INT PRIMARY KEY, EntryName STRING);
+CREATE TABLE Item_Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), PatientID INT, FOREIGN KEY (PatientID) REFERENCES Person(ID), PerformedDTTM DATE, EntryName STRING);
+CREATE TABLE Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), ItemID INT, FOREIGN KEY (ItemID) REFERENCES Item_Medication(ID), MedDictDE INT, FOREIGN KEY (MedDictDE) REFERENCES Medication_DE(ID));
+CREATE TABLE Medication_DE (ID INT PRIMARY KEY, NDC INT);
+CREATE TABLE NDCcodes (ID INT PRIMARY KEY, NDC INT, ingredient INT);
+"""
+  val hosp1:DatabaseDesc = DDLParser.parseAll(DDLParser.ddl, hosp1Ddl).get
 
   test("swobjects/tests/healthCare/lists-notBound/db.rq AS OPTIONAL") {
     val sparqlParser = Sparql()