From cb41cd63664880501b553ea5d9c9fef12f35b20f Mon Sep 17 00:00:00 2001 From: camby Date: Thu, 26 Dec 2024 11:41:32 +0800 Subject: [PATCH] [fix](variant) disable column name with dot character for variant type (#45927) Variant type column named with '.' character make be crashed, here disable it temporarily. --- .../doris/analysis/CreateTableStmt.java | 5 ++++ .../plans/commands/info/CreateTableInfo.java | 5 ++++ .../suites/ddl_p0/test_create_table.groovy | 30 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java index 333f4eabc6b8e8..3dccc18730afa7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java @@ -317,6 +317,11 @@ public void analyze(Analyzer analyzer) throws UserException { throw new AnalysisException( "Disable to create table column with name start with __DORIS_: " + columnNameUpperCase); } + if (Objects.equals(columnDef.getType(), Type.VARIANT) && columnNameUpperCase.indexOf('.') != -1) { + throw new AnalysisException( + "Disable to create table of `VARIANT` type column named with a `.` character: " + + columnNameUpperCase); + } if (Objects.equals(columnDef.getType(), Type.DATE) && Config.disable_datev1) { throw new AnalysisException("Disable to create table with `DATE` type columns, please use `DATEV2`."); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java index 638b87c07e0776..09c44626e784c7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java @@ -278,6 +278,11 @@ public void validate(ConnectContext ctx) { throw new AnalysisException( "Disable to create table column with name start with __DORIS_: " + columnNameUpperCase); } + if (columnDef.getType().isVariantType() && columnNameUpperCase.indexOf('.') != -1) { + throw new AnalysisException( + "Disable to create table of `VARIANT` type column named with a `.` character: " + + columnNameUpperCase); + } if (columnDef.getType().isDateType() && Config.disable_datev1) { throw new AnalysisException( "Disable to create table with `DATE` type columns, please use `DATEV2`."); diff --git a/regression-test/suites/ddl_p0/test_create_table.groovy b/regression-test/suites/ddl_p0/test_create_table.groovy index 1d3b8409d6566b..03de74bc2897d0 100644 --- a/regression-test/suites/ddl_p0/test_create_table.groovy +++ b/regression-test/suites/ddl_p0/test_create_table.groovy @@ -46,6 +46,21 @@ suite("sql_create_time_range_table") { ); """ + // variant type column named with '.' character is disabled + sql "DROP TABLE IF EXISTS disable_variant_column_with_dot" + test { + sql """ + CREATE TABLE disable_variant_column_with_dot ( + k int, + `v1.v2` variant + ) + DUPLICATE KEY (`k`) + DISTRIBUTED BY HASH(`k`) BUCKETS 1 + PROPERTIES ( "replication_num" = "1"); + """ + exception "Disable to create table" + } + // DDL/DML return 1 row and 1 column, the only value is update row count assertTrue(result1.size() == 1) assertTrue(result1[0].size() == 1) @@ -58,4 +73,19 @@ suite("sql_create_time_range_table") { def res_show = sql "show create table varchar_0_char_0" mustContain(res_show[0][1], "varchar(65533)") mustContain(res_show[0][1], "char(1)") + + // variant type column named with '.' character is disabled + sql "DROP TABLE IF EXISTS disable_variant_column_with_dot" + test { + sql """ + CREATE TABLE disable_variant_column_with_dot ( + k int, + `v1.v2` variant + ) + DUPLICATE KEY (`k`) + DISTRIBUTED BY HASH(`k`) BUCKETS 1 + PROPERTIES ( "replication_num" = "1"); + """ + exception "Disable to create table" + } }