From 08d439cde7608609fd5bdbf351d275c43e878a68 Mon Sep 17 00:00:00 2001 From: mch_ucchi <41606806+sohardforaname@users.noreply.github.com> Date: Sat, 7 Jan 2023 00:28:21 +0800 Subject: [PATCH] [feature](Nereids) add keyword rlike (#15647) --- .../org/apache/doris/nereids/DorisParser.g4 | 2 +- .../nereids/parser/LogicalPlanBuilder.java | 1 + .../data/nereids_syntax_p0/rlike.out | 15 +++++++++++ .../suites/nereids_syntax_p0/rlike.groovy | 27 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 regression-test/data/nereids_syntax_p0/rlike.out create mode 100644 regression-test/suites/nereids_syntax_p0/rlike.groovy diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 5da6610182..e594e100a5 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -249,7 +249,7 @@ booleanExpression predicate : NOT? kind=BETWEEN lower=valueExpression AND upper=valueExpression - | NOT? kind=(LIKE | REGEXP) pattern=valueExpression + | NOT? kind=(LIKE | REGEXP | RLIKE) pattern=valueExpression | NOT? kind=IN LEFT_PAREN expression (COMMA expression)* RIGHT_PAREN | NOT? kind=IN LEFT_PAREN query RIGHT_PAREN | IS NOT? kind=NULL diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 1792cbf687..01fa86ad79 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -1418,6 +1418,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { getExpression(ctx.pattern) ); break; + case DorisParser.RLIKE: case DorisParser.REGEXP: outExpression = new Regexp( valueExpression, diff --git a/regression-test/data/nereids_syntax_p0/rlike.out b/regression-test/data/nereids_syntax_p0/rlike.out new file mode 100644 index 0000000000..b0975708c2 --- /dev/null +++ b/regression-test/data/nereids_syntax_p0/rlike.out @@ -0,0 +1,15 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !regexp -- +Customer#000001309 + +-- !rlike -- +Customer#000001309 + +-- !not_regexp -- +Customer#000001303 +Customer#000001312 + +-- !not_rlike -- +Customer#000001303 +Customer#000001312 + diff --git a/regression-test/suites/nereids_syntax_p0/rlike.groovy b/regression-test/suites/nereids_syntax_p0/rlike.groovy new file mode 100644 index 0000000000..7d4cac4ec8 --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/rlike.groovy @@ -0,0 +1,27 @@ +// 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. + +suite("rlike") { + sql "use regression_test_nereids_syntax_p0" + sql "set enable_nereids_planner=true" + sql "set enable_fallback_to_original_planner=false" + + qt_regexp "select c_name from customer where c_name regexp '9' order by c_custkey" + qt_rlike "select c_name from customer where c_name rlike '9' order by c_custkey" + qt_not_regexp "select c_name from customer where c_name not regexp '9' order by c_custkey" + qt_not_rlike "select c_name from customer where c_name not rlike '9' order by c_custkey" +} \ No newline at end of file