Yingyi Bu has submitted this change and it was merged. Change subject: Fix the operator precedence of LIKE. ......................................................................
Fix the operator precedence of LIKE. Change-Id: I0cd4e2910d4055efa6f2d2a6de8b1ef8f67275e5 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1456 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> BAD: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Yingyi Bu <buyin...@gmail.com> --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj 4 files changed, 68 insertions(+), 2 deletions(-) Approvals: Yingyi Bu: Looks good to me, approved Jenkins: Verified; No violations found; No violations found; Verified 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; 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 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> 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 @@ 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) { @@ -1873,6 +1873,7 @@ return op==null? operand: op; } } + Expression BetweenExpr()throws ParseException: { @@ -1938,7 +1939,7 @@ 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 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; -- To view, visit https://asterix-gerrit.ics.uci.edu/1456 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0cd4e2910d4055efa6f2d2a6de8b1ef8f67275e5 Gerrit-PatchSet: 4 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Yingyi Bu <buyin...@gmail.com> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Till Westmann <ti...@apache.org> Gerrit-Reviewer: Yingyi Bu <buyin...@gmail.com>