chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r812234 - in /incubator/chemistry/trunk/chemistry/chemistry-commons/src: main/antlr3/org/apache/chemistry/cmissql/ main/antlr3/org/apache/chemistry/impl/simple/ test/gunit/org/apache/chemistry/cmissql/
Date Mon, 07 Sep 2009 17:34:48 GMT
Author: fguillaume
Date: Mon Sep  7 17:34:48 2009
New Revision: 812234

URL: http://svn.apache.org/viewvc?rev=812234&view=rev
Log:
CMIS-50: Add JOIN capability to the commons parser

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g?rev=812234&r1=812233&r2=812234&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
Mon Sep  7 17:34:48 2009
@@ -96,21 +96,36 @@
 from_clause: FROM^ table_reference;
 
 table_reference:
-      table_name
-    | table_name AS? correlation_name
-      -> ^(TABLE table_name correlation_name)
-    | joined_table
+    one_table table_join*
+    ;
+
+table_join:
+    join_kind one_table join_specification?
+    -> ^(JOIN join_kind one_table join_specification?)
     ;
 
-joined_table
-    : LPAR joined_table RPAR
-    //| table_reference join_type? 'JOIN' table_reference join_specification?
+one_table:
+      LPAR! table_reference RPAR!
+    | table_name
+        -> ^(TABLE table_name)
+    | table_name AS? correlation_name
+        -> ^(TABLE table_name correlation_name)
     ;
 
-join_type: INNER | LEFT OUTER?;
+join_kind:
+      JOIN
+        -> INNER
+    | INNER JOIN
+        -> INNER
+    | LEFT OUTER? JOIN
+        -> LEFT
+    | RIGHT OUTER? JOIN
+        -> RIGHT
+    ;
 
 join_specification:
-    ON^ column_reference EQ! column_reference;
+    ON^ column_reference EQ column_reference
+    ;
 
 where_clause: WHERE^ search_condition;
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g?rev=812234&r1=812233&r2=812234&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
Mon Sep  7 17:34:48 2009
@@ -107,14 +107,29 @@
     ;
 
 table_reference returns [String tableName]:
-      table_name
-        {
-            $tableName = $table_name.text;
-        }
-    | ^(TABLE table_name correlation_name)
-        {
-            $tableName = $table_name.text;
-        }
+    one_table table_join*
+      {
+          $tableName = $one_table.tableName;
+          // TODO joins
+      }
+    ;
+
+table_join:
+    ^(JOIN join_kind one_table join_specification?)
+    ;
+
+one_table returns [String tableName]:
+    ^(TABLE table_name correlation_name?)
+      {
+          $tableName = $table_name.text;
+      }
+    ;
+
+join_kind:
+    INNER | LEFT | OUTER;
+
+join_specification:
+    ^(ON column_reference EQ column_reference)
     ;
 
 where_clause returns [boolean matches]:

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite?rev=812234&r1=812233&r2=812234&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Mon Sep  7 17:34:48 2009
@@ -73,10 +73,18 @@
 "foo" -> (COL foo)
 "bar.foo" -> (COL bar foo)
 
-table_reference:
-"foo" -> "foo"
+from_clause:
+"FROM foo JOIN bar ON x = y" -> (FROM (TABLE foo) (JOIN INNER (TABLE bar) (ON (COL x)
= (COL y))))
+
+table_join:
+"LEFT OUTER JOIN foo ON x = y" -> (JOIN LEFT (TABLE foo) (ON (COL x) = (COL y)))
+"INNER JOIN foo" -> (JOIN INNER (TABLE foo))
+
+one_table:
+"foo" -> (TABLE foo)
 "foo bar" -> (TABLE foo bar)
 "foo AS bar" -> (TABLE foo bar)
+"(foo)" -> (TABLE foo)
 
 in_predicate:
 "foo IN ( 'a', 'b', 'c')" -> (BIN_OP IN (COL foo) (LIST 'a' 'b' 'c'))
@@ -113,9 +121,9 @@
 "a = 1 AND b <> 2 OR c >= 3 AND NOT d <= 4" -> (OR (AND (BIN_OP = (COL a)
1) (BIN_OP <> (COL b) 2)) (AND (BIN_OP >= (COL c) 3) (NOT (BIN_OP <= (COL d) 4))))
 
 query:
-"SELECT * FROM Document" -> (SELECT * (FROM Document))
-"SELECT a, b, c FROM Document" -> (SELECT (LIST (COL a) (COL b) (COL c)) (FROM Document))
-"SELECT a, b FROM Document ORDER BY a, b" -> (SELECT (LIST (COL a) (COL b)) (FROM Document)
(ORDER_BY a ASC b ASC))
+"SELECT * FROM Document" -> (SELECT * (FROM (TABLE Document)))
+"SELECT a, b, c FROM Document" -> (SELECT (LIST (COL a) (COL b) (COL c)) (FROM (TABLE
Document)))
+"SELECT a, b FROM Document ORDER BY a, b" -> (SELECT (LIST (COL a) (COL b)) (FROM (TABLE
Document)) (ORDER_BY a ASC b ASC))
 
 
 // Examples from the specs.
@@ -124,7 +132,7 @@
 SELECT TITLE, AUTHORS, DATE
 FROM WHITE_PAPER
 WHERE ( IN_TREE('ID00093854763') ) AND ( 'SMITH' = ANY AUTHORS )
->> -> (SELECT (LIST (COL TITLE) (COL AUTHORS) (COL DATE)) (FROM WHITE_PAPER) (WHERE
(AND (FUNC IN_TREE 'ID00093854763') (BIN_OP_ANY = 'SMITH' (COL AUTHORS)))))
+>> -> (SELECT (LIST (COL TITLE) (COL AUTHORS) (COL DATE)) (FROM (TABLE WHITE_PAPER))
(WHERE (AND (FUNC IN_TREE 'ID00093854763') (BIN_OP_ANY = 'SMITH' (COL AUTHORS)))))
 
 <<
 SELECT OBJECT_ID, SCORE() AS X, DESTINATION, DEPARTURE_DATES
@@ -141,8 +149,8 @@
   ( ANY FEATURES IN ('NAVIGATION SYSTEM', 'SATELLITE RADIO', 'MP3' ) )
 >> OK
 
-/* JOINs not working yet.
-<<SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES
+<<
+SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES
 FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM
-WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )>>
OK
-*/
+WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )
+>> OK



Mime
View raw message