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 2016/07/27 21:27:51 UTC

asterixdb git commit: ASTERIXDB-1527: fix operator precedence order.

Repository: asterixdb
Updated Branches:
  refs/heads/master 17da21a9c -> 79ccdac8a


ASTERIXDB-1527: fix operator precedence order.

Change-Id: Ib16477c4fad341685e9b1349f40eeabfc74b0165
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1025
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>


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

Branch: refs/heads/master
Commit: 79ccdac8a7d2f6d39fce8cc15e3bd4b40bec8e81
Parents: 17da21a
Author: Yingyi Bu <yi...@couchbase.com>
Authored: Tue Jul 26 23:49:24 2016 -0700
Committer: Yingyi Bu <bu...@gmail.com>
Committed: Wed Jul 27 14:27:19 2016 -0700

----------------------------------------------------------------------
 .../queries/numeric/caret1/caret1.1.query.aql   | 20 ++++++++++
 .../numeric/caret1/caret1.1.query.sqlpp         | 20 ++++++++++
 .../results/numeric/caret1/caret1.1.adm         |  1 +
 .../src/test/resources/runtimets/testsuite.xml  |  5 +++
 .../resources/runtimets/testsuite_sqlpp.xml     |  5 +++
 .../asterix-lang-aql/src/main/javacc/AQL.jj     | 42 +++++++++++++++++---
 .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj | 40 ++++++++++++++++---
 7 files changed, 123 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/asterixdb/asterix-app/src/test/resources/runtimets/queries/numeric/caret1/caret1.1.query.aql
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/numeric/caret1/caret1.1.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/numeric/caret1/caret1.1.query.aql
new file mode 100644
index 0000000..f63ab15
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/numeric/caret1/caret1.1.query.aql
@@ -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.
+ */
+
+2*3^2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/caret1/caret1.1.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/caret1/caret1.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/caret1/caret1.1.query.sqlpp
new file mode 100644
index 0000000..e31609d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/caret1/caret1.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 ELEMENT 2*3^2;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret1/caret1.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret1/caret1.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret1/caret1.1.adm
new file mode 100644
index 0000000..3c03207
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret1/caret1.1.adm
@@ -0,0 +1 @@
+18

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 279522a..deee18f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4035,6 +4035,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
+      <compilation-unit name="caret1">
+        <output-dir compare="Text">caret1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="numeric">
       <compilation-unit name="abs0">
         <output-dir compare="Text">abs0</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/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 748d924..1465ca7 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -3830,6 +3830,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
+      <compilation-unit name="caret1">
+        <output-dir compare="Text">caret1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="numeric">
       <compilation-unit name="abs0">
         <output-dir compare="Text">abs0</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
index 7701278..0c8a911 100644
--- a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
+++ b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
@@ -1740,14 +1740,14 @@ Expression MultExpr()throws ParseException:
   Expression operand = null;
 }
 {
-    operand = UnionExpr()
+    operand = ExponentExpr()
 
-    (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
+    (( <MUL> | <DIV> | <MOD> | <IDIV>)
       {
         if (op == null) {
           op = new OperatorExpr();
-        op.addOperand(operand);
-        op.setCurrentop(true);
+          op.addOperand(operand);
+          op.setCurrentop(true);
         }
         try{
           op.addOperator(token.image);
@@ -1755,7 +1755,7 @@ Expression MultExpr()throws ParseException:
           throw new ParseException(e.getMessage());
         }
     }
-    operand = UnionExpr()
+    operand = ExponentExpr()
     {
        op.addOperand(operand);
     }
@@ -1766,6 +1766,38 @@ Expression MultExpr()throws ParseException:
      }
 }
 
+Expression ExponentExpr()throws ParseException:
+{
+  OperatorExpr op = null;
+  Expression operand = null;
+}
+{
+    operand = UnionExpr()
+
+    ( <CARET>
+      {
+        if (op == null) {
+          op = new OperatorExpr();
+          op.addOperand(operand);
+          op.setCurrentop(true);
+        }
+        try{
+          op.addOperator(token.image);
+        } catch (AsterixException e){
+          throw new ParseException(e.getMessage());
+        }
+    }
+    operand = UnionExpr()
+    {
+       op.addOperand(operand);
+    }
+    )?
+
+    {
+       return op==null?operand:op;
+    }
+}
+
 Expression UnionExpr() throws ParseException:
 {
     UnionExpr union = null;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79ccdac8/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 d496027..603295a 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -1822,14 +1822,14 @@ Expression MultExpr()throws ParseException:
   Expression operand = null;
 }
 {
-    operand = UnaryExpr()
+    operand = ExponentExpr()
 
-    (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
+    (( <MUL> | <DIV> | <MOD> | <IDIV>)
       {
         if (op == null) {
           op = new OperatorExpr();
-        op.addOperand(operand);
-        op.setCurrentop(true);
+          op.addOperand(operand);
+          op.setCurrentop(true);
         }
         try{
             op.addOperator(token.image);
@@ -1837,7 +1837,7 @@ Expression MultExpr()throws ParseException:
             throw new ParseException(e.getMessage());
         }
     }
-    operand = UnaryExpr()
+    operand = ExponentExpr()
     {
        op.addOperand(operand);
     }
@@ -1848,6 +1848,36 @@ Expression MultExpr()throws ParseException:
      }
 }
 
+Expression ExponentExpr()throws ParseException:
+{
+  OperatorExpr op = null;
+  Expression operand = null;
+}
+{
+    operand = UnaryExpr()
+    (<CARET>
+    {
+        if (op == null) {
+          op = new OperatorExpr();
+          op.addOperand(operand);
+          op.setCurrentop(true);
+        }
+        try{
+            op.addOperator(token.image);
+        } catch (Exception e){
+            throw new ParseException(e.getMessage());
+        }
+    }
+    operand = UnaryExpr()
+    {
+       op.addOperand(operand);
+    }
+    )?
+    {
+       return op==null?operand:op;
+    }
+}
+
 Expression UnaryExpr() throws ParseException:
 {
     boolean not = false;