Yingyi Bu has submitted this change and it was merged. Change subject: ASTERIXDB-1527: fix operator precedence order. ......................................................................
ASTERIXDB-1527: fix operator precedence order. Change-Id: Ib16477c4fad341685e9b1349f40eeabfc74b0165 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1025 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Till Westmann <[email protected]> --- A asterixdb/asterix-app/src/test/resources/runtimets/queries/numeric/caret1/caret1.1.query.aql A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/caret1/caret1.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret1/caret1.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj 7 files changed, 128 insertions(+), 15 deletions(-) Approvals: Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; Verified 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 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 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 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> 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> 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,46 @@ 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); + } catch (AsterixException e){ + throw new ParseException(e.getMessage()); + } + } + operand = ExponentExpr() + { + op.addOperand(operand); + } + )* + + { + return op==null?operand:op; + } +} + +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); @@ -1759,11 +1791,11 @@ { op.addOperand(operand); } - )* + )? - { + { return op==null?operand:op; - } + } } Expression UnionExpr() throws ParseException: 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,45 @@ 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); + } catch (Exception e){ + throw new ParseException(e.getMessage()); + } + } + operand = ExponentExpr() + { + op.addOperand(operand); + } + )* + + { + return op==null?operand:op; + } +} + +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); @@ -1841,11 +1872,10 @@ { op.addOperand(operand); } - )* - - { + )? + { return op==null?operand:op; - } + } } Expression UnaryExpr() throws ParseException: -- To view, visit https://asterix-gerrit.ics.uci.edu/1025 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib16477c4fad341685e9b1349f40eeabfc74b0165 Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Yingyi Bu <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]> Gerrit-Reviewer: Yingyi Bu <[email protected]>
