From ea1e8fa15da2a233b45618144ec42703a222f6ec Mon Sep 17 00:00:00 2001 From: LiBinfeng <46676950+LiBinfeng-01@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:50:28 +0800 Subject: [PATCH] [Fix](Nereids) fix create table as select of view with unknowed length character type (#25471) Problem: when create table as select from a view with unknown length character type, be would return an error of inserting data failed Example: doris/regression-test/suites/ddl_p0/test_ctas.groovy Reason & Solved: BE can not derive varchar length automaticly so FE should tell BE to maximize the size of varchar type --- .../plans/commands/CreateTableCommand.java | 4 +- .../suites/ddl_p0/test_ctas.groovy | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java index 08a10b914c..5f38170ec8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java @@ -108,8 +108,8 @@ public class CreateTableCommand extends Command implements ForwardWithSync { } else if (i == 0 && dataType.isStringType()) { dataType = VarcharType.createVarcharType(ScalarType.MAX_VARCHAR_LENGTH); } else if (dataType instanceof CharacterType) { - // if column is not come from column, we should set varchar length to max - if (((CharacterType) dataType).getLen() > 0 && !s.isColumnFromTable()) { + // if column is not come from table, we should set varchar length to max + if (!s.isColumnFromTable()) { dataType = VarcharType.createVarcharType(ScalarType.MAX_VARCHAR_LENGTH); } } diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy index db9385a841..d634dc91e0 100644 --- a/regression-test/suites/ddl_p0/test_ctas.groovy +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -252,5 +252,43 @@ suite("test_ctas") { sql 'drop table c' sql 'drop table test_date_v2' } + + try { + sql '''set enable_nereids_planner=true;''' + sql'''CREATE TABLE `test_ctas_of_view` ( + `l_varchar` varchar(65533) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`l_varchar`) + COMMENT 'OLAP\' + DISTRIBUTED BY HASH(`l_varchar`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + );''' + + sql '''insert into test_ctas_of_view values ('a');''' + + sql '''CREATE VIEW `ctas_view` COMMENT 'VIEW' + AS SELECT `l_varchar` AS `l_varchar_1`, + CAST(row_number() OVER (ORDER BY `l_varchar` ASC NULLS FIRST) AS CHARACTER) AS `l_varchar_2` + FROM test_ctas_of_view;''' + + sql '''create table test_ctas + PROPERTIES ( "replication_allocation" = "tag.location.default: 1") + as select l_varchar_1 + from ctas_view;''' + + String desc = sql 'desc test_ctas' + assertTrue(desc.contains('Yes')) + + } finally { + sql 'drop table test_ctas' + sql 'drop table test_ctas_of_view' + sql 'drop view ctas_view' + } }