From 407ccaaff70d28af00cd295d30bc1208b8b85385 Mon Sep 17 00:00:00 2001 From: mch_ucchi <41606806+sohardforaname@users.noreply.github.com> Date: Thu, 16 Feb 2023 20:01:13 +0800 Subject: [PATCH] [FIx](planner) create table as select with null_type select item cause be core bug (#16778) sql: create table t as select null as k will cause be core sometime. now we change it null_type to tinyint nullable to avoid it. --- .../java/org/apache/doris/datasource/InternalCatalog.java | 4 ++++ regression-test/suites/ddl_p0/test_ctas.groovy | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index e7d38ba957..240ce9fbf8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -1239,6 +1239,10 @@ public class InternalCatalog implements CatalogIf { } else if (resultType.isDecimalV3()) { typeDef = new TypeDef(ScalarType.createDecimalV3Type(resultType.getPrecision(), ((ScalarType) resultType).getScalarScale())); + } else if (resultType.isNull()) { + // if typeDef is NULL_TYPE, be will core when executing CTAS expression, + // we change it to tinyint nullable. + typeDef = TypeDef.create(PrimitiveType.TINYINT); } else { typeDef = new TypeDef(resultExpr.getType()); } diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy index bdfb6d82b9..744aa7232b 100644 --- a/regression-test/suites/ddl_p0/test_ctas.groovy +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -90,6 +90,11 @@ suite("test_ctas") { qt_select """select * from test_ctas_json_object1 order by c1;""" + sql """create table a properties("replication_num"="1") as select null as c;""" + test { + sql "select * from a" + result([[null]]) + } } finally { sql """ DROP TABLE IF EXISTS test_ctas """ @@ -101,6 +106,8 @@ suite("test_ctas") { sql """ DROP TABLE IF EXISTS test_ctas_json_object """ sql """ DROP TABLE IF EXISTS test_ctas_json_object1 """ + + sql """drop table if exists a""" } }