You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by bu...@apache.org on 2017/01/22 21:20:13 UTC

asterixdb git commit: Fix the operator precedence of LIKE.

Repository: asterixdb
Updated Branches:
  refs/heads/master 0af5b5df8 -> 6e6a80c44


Fix the operator precedence of LIKE.

Change-Id: I0cd4e2910d4055efa6f2d2a6de8b1ef8f67275e5
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1456
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
BAD: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <bu...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/6e6a80c4
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/6e6a80c4
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/6e6a80c4

Branch: refs/heads/master
Commit: 6e6a80c44eeb6d721795e5279dcbfa9df79c2d9c
Parents: 0af5b5d
Author: Yingyi Bu <yi...@couchbase.com>
Authored: Sat Jan 21 20:18:49 2017 -0800
Committer: Yingyi Bu <bu...@gmail.com>
Committed: Sun Jan 22 13:19:44 2017 -0800

----------------------------------------------------------------------
 .../comparison/like/like.1.query.sqlpp          | 20 +++++++++
 .../results/comparison/like/like.1.adm          |  1 +
 .../resources/runtimets/testsuite_sqlpp.xml     |  5 +++
 .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj | 44 +++++++++++++++++++-
 4 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6e6a80c4/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
new file mode 100644
index 0000000..d6a1408
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+SELECT VALUE "ab"||"c" LIKE "%c" = TRUE;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6e6a80c4/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm
new file mode 100644
index 0000000..f32a580
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm
@@ -0,0 +1 @@
+true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6e6a80c4/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 9bd2126..e5c5bdd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1063,6 +1063,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
+      <compilation-unit name="like">
+        <output-dir compare="Text">like</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="comparison">
       <compilation-unit name="lt_01">
         <output-dir compare="Text">lt_01</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6e6a80c4/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 047fcc4..81f00ee 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -1828,7 +1828,7 @@ Expression RelExpr()throws ParseException:
     operand = BetweenExpr()
 
     (
-      LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? (<LIKE>|<IN>))
+      LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>)
         {
           String mhint = getHint(token);
           if (mhint != null) {
@@ -1874,6 +1874,7 @@ Expression RelExpr()throws ParseException:
      }
 }
 
+
 Expression BetweenExpr()throws ParseException:
 {
   boolean not = false;
@@ -1938,7 +1939,7 @@ Expression IsExpr() throws ParseException:
     boolean not = false;
 }
 {
-    operand = ConcatExpr()
+    operand = LikeExpr()
     ( <IS> (<NOT> { not = true; })? (<NULL> | <MISSING> | <UNKOWN>)
       {
         String functionName = "is-" + token.image.toLowerCase();
@@ -1955,6 +1956,45 @@ Expression IsExpr() throws ParseException:
     }
 }
 
+
+Expression LikeExpr()throws ParseException:
+{
+  boolean not = false;
+  OperatorExpr op = null;
+  Expression operand = null;
+}
+{
+    operand = ConcatExpr()
+    (
+        LOOKAHEAD(2)
+        (<NOT> { not = true; })? <LIKE>
+        {
+          op = new OperatorExpr();
+          op.addOperand(operand);
+          op.setCurrentop(true);
+
+          String operator = token.image.toLowerCase();
+          if (not) {
+            operator = "not_" + operator;
+          }
+          try{
+            op.addOperator(operator);
+          } catch (CompilationException e){
+            throw new ParseException(e.getMessage());
+          }
+        }
+
+        operand = ConcatExpr()
+        {
+          op.addOperand(operand);
+        }
+     )?
+
+     {
+       return op == null ? operand : op;
+     }
+}
+
 Expression ConcatExpr()throws ParseException:
 {
   OperatorExpr op = null;