This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d19530c4c28 [Fix](Nereids) fix leading hint dealing with big brace
(#29405)
d19530c4c28 is described below
commit d19530c4c28baf1fc5498590de6380b542a2fcde
Author: LiBinfeng <[email protected]>
AuthorDate: Wed Jan 3 18:13:38 2024 +0800
[Fix](Nereids) fix leading hint dealing with big brace (#29405)
Co-authored-by: libinfeng <[email protected]>
---
.../org/apache/doris/nereids/hint/LeadingHint.java | 17 ++++++++-
.../data/nereids_p0/hint/fix_leading.out | 21 +++++++++++
.../suites/nereids_p0/hint/fix_leading.groovy | 43 ++++++++++++++++++++++
3 files changed, 79 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java
index 97af2e26223..4d1abbbf951 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java
@@ -83,15 +83,28 @@ public class LeadingHint extends Hint {
super(hintName);
this.originalString = originalString;
int level = 0;
+ Stack<Boolean> brace = new Stack<>();
+ String lastParameter = "";
for (String parameter : parameters) {
if (parameter.equals("{")) {
- ++level;
+ if (lastParameter.equals("}")) {
+ level += 2;
+ brace.push(true);
+ } else {
+ ++level;
+ brace.push(false);
+ }
} else if (parameter.equals("}")) {
- level--;
+ if (brace.pop().equals(true)) {
+ level -= 2;
+ } else {
+ level--;
+ }
} else {
tablelist.add(parameter);
levellist.add(level);
}
+ lastParameter = parameter;
}
}
diff --git a/regression-test/data/nereids_p0/hint/fix_leading.out
b/regression-test/data/nereids_p0/hint/fix_leading.out
new file mode 100644
index 00000000000..86abd918f91
--- /dev/null
+++ b/regression-test/data/nereids_p0/hint/fix_leading.out
@@ -0,0 +1,21 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select1 --
+PhysicalResultSink
+--PhysicalDistribute
+----PhysicalProject
+------hashJoin[INNER_JOIN] hashCondition=((t1.c1 = t3.c3) and (t1.c1 = t4.c4))
otherCondition=()
+--------hashJoin[INNER_JOIN] hashCondition=((t1.c1 = t2.c2)) otherCondition=()
+----------PhysicalOlapScan[t1]
+----------PhysicalDistribute
+------------PhysicalOlapScan[t2]
+--------PhysicalDistribute
+----------NestedLoopJoin[CROSS_JOIN]
+------------PhysicalOlapScan[t3]
+------------PhysicalDistribute
+--------------PhysicalOlapScan[t4]
+
+Hint log:
+Used: leading({ t1 t2 } { t3 t4 })
+UnUsed:
+SyntaxError:
+
diff --git a/regression-test/suites/nereids_p0/hint/fix_leading.groovy
b/regression-test/suites/nereids_p0/hint/fix_leading.groovy
new file mode 100644
index 00000000000..b1da3b44b69
--- /dev/null
+++ b/regression-test/suites/nereids_p0/hint/fix_leading.groovy
@@ -0,0 +1,43 @@
+/*
+ * 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("fix_leading") {
+ // create database and tables
+ sql 'DROP DATABASE IF EXISTS fix_leading'
+ sql 'CREATE DATABASE IF NOT EXISTS fix_leading'
+ sql 'use fix_leading'
+
+ // setting planner to nereids
+ sql 'set enable_nereids_planner=true'
+ sql 'set enable_fallback_to_original_planner=false'
+
+ // create tables
+ sql """drop table if exists t1;"""
+ sql """drop table if exists t2;"""
+ sql """drop table if exists t3;"""
+ sql """drop table if exists t4;"""
+
+ sql """create table t1 (c1 int, c11 int) distributed by hash(c1) buckets 3
properties('replication_num' = '1');"""
+ sql """create table t2 (c2 int, c22 int) distributed by hash(c2) buckets 3
properties('replication_num' = '1');"""
+ sql """create table t3 (c3 int, c33 int) distributed by hash(c3) buckets 3
properties('replication_num' = '1');"""
+ sql """create table t4 (c4 int, c44 int) distributed by hash(c4) buckets 3
properties('replication_num' = '1');"""
+
+ // bug fix 1: {t1 t2}{t3 t4} miss levels
+ qt_select1 """explain shape plan select /*+ leading({t1 t2}{t3 t4}) */ *
from t1 join t2 on c1 = c2 join t3 on c1 = c3 join t4 on c1 = c4;"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]