chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r901328 - in /incubator/chemistry/trunk/chemistry: chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Date Wed, 20 Jan 2010 18:51:16 GMT
Author: fguillaume
Date: Wed Jan 20 18:51:16 2010
New Revision: 901328

URL: http://svn.apache.org/viewvc?rev=901328&view=rev
Log:
Allow parsing of SCORE() in queries

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

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=901328&r1=901327&r2=901328&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
Wed Jan 20 18:51:16 2010
@@ -96,8 +96,19 @@
         {
             $value = $column_reference.value;
         }
-//    | string_value_function
-//    | numeric_value_function
+    | ^(FUNC func_name arg*)
+        {
+            int func = $func_name.start.getType();
+            switch (func) {
+                case SCORE:
+                    $value = Double.valueOf(1);
+                    break;
+                // case ID:
+                // TODO provide extension points for other functions
+                default:
+                    throw new UnwantedTokenException(Token.INVALID_TOKEN_TYPE, input);
+            }
+        }
     ;
 
 column_reference returns [Object value]:
@@ -109,6 +120,9 @@
       }
     ;
 
+// multi_valued_column_reference returns [Object value]:
+//    ^(COL qualifier? column_name)
+
 qualifier:
       table_name
 //    | correlation_name
@@ -180,11 +194,11 @@
 
 predicate returns [boolean matches]
 @init {
-    List<Object> literals = new ArrayList<Object>();
+    List<Object> literals;
 }:
-      ^(UN_OP IS_NULL un_arg) { $matches = $un_arg.value == null; }
-    | ^(UN_OP IS_NOT_NULL un_arg) { $matches = $un_arg.value != null; }
-    | ^(BIN_OP bin_op arg1=bin_arg arg2=bin_arg)
+      ^(UN_OP IS_NULL arg) { $matches = $arg.value == null; }
+    | ^(UN_OP IS_NOT_NULL arg) { $matches = $arg.value != null; }
+    | ^(BIN_OP bin_op arg1=arg arg2=arg)
         {
             int token = $bin_op.start.getType();
             Object value1 = $arg1.value;
@@ -196,13 +210,21 @@
                 case NEQ:
                     $matches = value1 != null && value2 != null && ! value1.equals(value2);
                     break;
+                case LT:
+                case LTEQ:
+                case GT:
+                case GTEQ:
+                case LIKE:
+                case NOT_LIKE:
                 default:
                     throw new UnwantedTokenException(token, input);
             }
         }
-    | ^(FUNC func_name (literal { literals.add($literal.value); })*)
+    // | ^(BIN_OP_ANY bin_op_any arg mvc=multi_valued_column_reference)
+    | ^(FUNC bool_func_name { literals = new ArrayList<Object>(); }
+         (literal { literals.add($literal.value); })*)
         {
-            int func = $func_name.start.getType();
+            int func = $bool_func_name.start.getType();
             switch (func) {
                 case IN_FOLDER:
                     $matches = connection.isInFolder(data, literals.get(0));
@@ -220,37 +242,26 @@
         }
     ;
 
-un_arg returns [Object value]:
-    column_reference
-      {
-          $value = $column_reference.value;
-      }
-    ;
-
 bin_op:
     EQ | NEQ | LT | GT | LTEQ | GTEQ | LIKE | NOT_LIKE;
 
-bin_arg returns [Object value]
+func_name:
+    SCORE | ID;
+
+bool_func_name:
+    IN_FOLDER | IN_TREE | CONTAINS | ID;
+
+arg returns [Object value]
 @init {
-    List<Object> literals = new ArrayList<Object>();
+    List<Object> literals;
 }:
-      value_expression
-        {
-            $value = $value_expression.value;
-        }
-    | literal
-        {
-            $value = $literal.value;
-        }
-    | ^(LIST (literal { literals.add($literal.value); })+)
-        {
-            $value = literals;
-        }
+      v=value_expression { $value = $v.value; }
+    | l=literal { $value = $l.value; }
+    | ^(LIST { literals = new ArrayList<Object>(); }
+         (l=literal { literals.add($l.value); } )+)
+            { $value = literals; }
     ;
 
-func_name:
-    IN_FOLDER | IN_TREE | CONTAINS | ID;
-
 literal returns [Object value]:
       NUM_LIT
         {
@@ -279,6 +290,3 @@
 
 column_name:
     ID;
-
-multi_valued_column_name:
-    ID;

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=901328&r1=901327&r2=901328&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Wed Jan 20 18:51:16 2010
@@ -311,6 +311,11 @@
         res = conn.query("SELECT * FROM cmis:document WHERE CONTAINS('small')",
                 false);
         assertEquals(1, res.size());
+
+        // SCORE
+        res = conn.query("SELECT cmis:name, SCORE() FROM cmis:document WHERE CONTAINS('small')",
+                false);
+        assertEquals(1, res.size());
     }
 
     public void testGetObjectByPath() {



Mime
View raw message