From 50d9f35f63dfcbbf07636be9d73762e86bd76acf Mon Sep 17 00:00:00 2001 From: AKIRA <33112463+Kikyou1997@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:12:28 +0900 Subject: [PATCH] [fix](planner) NPE when use ctas to create table (#18973) This is caused by expr in orderbyelements is not analyzed. --- .../doris/analysis/FunctionCallExpr.java | 5 +++ .../suites/ddl_p0/test_ctas.groovy | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index a71a7c9f0c..fcf8250739 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1630,6 +1630,11 @@ public class FunctionCallExpr extends Expr { } // rewrite return type if is nested type function analyzeNestedFunction(); + for (OrderByElement o : orderByElements) { + if (!o.getExpr().isAnalyzed) { + o.getExpr().analyzeImpl(analyzer); + } + } } // if return type is nested type, need to be determined the sub-element type diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy index e17b82b2ec..27e12df4dd 100644 --- a/regression-test/suites/ddl_p0/test_ctas.groovy +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -152,6 +152,32 @@ suite("test_ctas") { and substring(col8, 1, 10) = '1451601'; """ + sql """ + DROP TABLE IF EXISTS tbl_3210581 + """ + + sql """ + CREATE TABLE tbl_3210581 (col1 varchar(11451) not null, col2 int not null, col3 int not null) + UNIQUE KEY(`col1`) + DISTRIBUTED BY HASH(col1) + BUCKETS 3 + PROPERTIES( + "replication_num"="1" + ) + """ + + sql """ + DROP TABLE IF EXISTS ctas_113815; + """ + + sql """ + create table ctas_113815 + PROPERTIES('replication_num' = '1') + as + select group_concat(col1 ORDER BY col1) from `tbl_3210581` + group by `col2`; + """ + } finally { sql """ DROP TABLE IF EXISTS test_ctas """ @@ -168,6 +194,14 @@ suite("test_ctas") { sql """DROP TABLE IF EXISTS test_tbl_81748325""" sql """DROP TABLE IF EXISTS test_tbl_3156019""" + + sql """ + DROP TABLE IF EXISTS tbl_3210581 + """ + + sql """ + DROP TABLE IF EXISTS ctas_113815 + """ } }