This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit f058a4641ba9459e0e539059e03b00997957aa6b Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Thu Apr 6 12:50:12 2023 +0900 [fix](planner) trying register constnat slotRef to table cause NPE (#18356) could reproduced by: CREATE TABLE t ( name varchar(128) ) ENGINE=OLAP UNIQUE KEY(name) DISTRIBUTED BY HASH(name) BUCKETS 1; insert into t values('abc'); SELECT cd FROM (SELECT cast(now() as string) cd FROM t) t1 JOIN (select cast(now() as string) td from t GROUP BY now()) t2 ON t1.cd = t2.td; ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: null --- .../java/org/apache/doris/analysis/Analyzer.java | 10 ++-- .../org/apache/doris/planner/QueryPlanTest.java | 1 - .../data/query_p0/join/join_on_view.out | 3 + .../suites/query_p0/aggregate/agg_on_view.groovy | 12 +++- .../suites/query_p0/join/join_on_view.groovy | 66 ++++++++++++++++++++++ 5 files changed, 84 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java index 3a0b762806..c44df2d2bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java @@ -1173,7 +1173,7 @@ public class Analyzer { registerConstantConjunct(id, conjunct); } } - markConstantConjunct(conjunct, fromHavingClause); + markConstantConjunct(conjunct, fromHavingClause, false); } } @@ -1189,7 +1189,7 @@ public class Analyzer { } public void registerMigrateFailedConjuncts(InlineViewRef ref, Expr e) throws AnalysisException { - markConstantConjunct(e, false); + markConstantConjunct(e, false, false); Set<Expr> exprSet = globalState.migrateFailedConjuncts.computeIfAbsent(ref, (k) -> new HashSet<>()); exprSet.add(e); } @@ -1802,7 +1802,7 @@ public class Analyzer { if (rhsRef.getJoinOp().isInnerJoin()) { globalState.ijClauseByConjunct.put(conjunct.getId(), rhsRef); } - markConstantConjunct(conjunct, false); + markConstantConjunct(conjunct, false, true); } } @@ -1814,9 +1814,9 @@ public class Analyzer { * No-op if the conjunct is not constant or is outer joined. * Throws an AnalysisException if there is an error evaluating `conjunct` */ - private void markConstantConjunct(Expr conjunct, boolean fromHavingClause) + private void markConstantConjunct(Expr conjunct, boolean fromHavingClause, boolean join) throws AnalysisException { - if (!conjunct.isConstant() || isOjConjunct(conjunct)) { + if (!conjunct.isConstant() || isOjConjunct(conjunct) || join) { return; } if ((!fromHavingClause && !hasEmptySpjResultSet) diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java index 42179fbd5e..8306c6ff14 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java @@ -1538,7 +1538,6 @@ public class QueryPlanTest extends TestWithFeService { sqls.add("explain select k3, dense_rank() OVER () AS rank FROM baseall where 1 =2;"); sqls.add("explain select rank from (select k3, dense_rank() OVER () AS rank FROM baseall) a where 1 =2;"); sqls.add("explain select * from baseall join bigtable as b where 1 = 2"); - sqls.add("explain select * from baseall join bigtable as b on null = 2"); for (String sql : sqls) { String explainString = getSQLPlanOrErrorMsg(sql); diff --git a/regression-test/data/query_p0/join/join_on_view.out b/regression-test/data/query_p0/join/join_on_view.out new file mode 100644 index 0000000000..9c9c4c6c8a --- /dev/null +++ b/regression-test/data/query_p0/join/join_on_view.out @@ -0,0 +1,3 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- + diff --git a/regression-test/suites/query_p0/aggregate/agg_on_view.groovy b/regression-test/suites/query_p0/aggregate/agg_on_view.groovy index 9f700283e1..ad08521638 100644 --- a/regression-test/suites/query_p0/aggregate/agg_on_view.groovy +++ b/regression-test/suites/query_p0/aggregate/agg_on_view.groovy @@ -16,8 +16,12 @@ // under the License. suite("agg_on_view") { + + sql """ + drop table if exists agg_on_view_test; + """ sql """ - create table test ( + create table agg_on_view_test ( id int, user_id int, name varchar(20) @@ -34,7 +38,11 @@ suite("agg_on_view") { from ( select *, "abc" as tag - from test limit 10)t + from agg_on_view_test limit 10)t group by user_id,tag """ + + sql """ + drop table agg_on_view_test; + """ } \ No newline at end of file diff --git a/regression-test/suites/query_p0/join/join_on_view.groovy b/regression-test/suites/query_p0/join/join_on_view.groovy new file mode 100644 index 0000000000..0ac951b9b6 --- /dev/null +++ b/regression-test/suites/query_p0/join/join_on_view.groovy @@ -0,0 +1,66 @@ +// 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("join_on_view") { + sql """ + drop table if exists jov_t1; + """ + sql """ + drop table if exists jov_t2; + """ + sql """ + CREATE TABLE jov_t1 ( + id int(11) NOT NULL COMMENT '' + ) ENGINE=OLAP + UNIQUE KEY(id) + COMMENT "OLAP" + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ + CREATE TABLE jov_t2 ( + name varchar(128) COMMENT '' + ) ENGINE=OLAP + UNIQUE KEY(name) + COMMENT "OLAP" + DISTRIBUTED BY HASH(name) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + qt_sql """ + SELECT cd + FROM + (SELECT CURDATE() cd + FROM jov_t1) tbl1 + JOIN + (select cast(now() as string) td + from jov_t2 b + GROUP BY now()) tbl2 + ON tbl1.cd = tbl2.td; + """ + + sql """ + drop table jov_t1; + """ + sql """ + drop table jov_t2; + """ +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org