From 3fa707a666869ef1c7915f2f13ec939fb6417674 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Fri, 5 Jul 2024 15:17:55 +0800 Subject: [PATCH 1/2] [Fix](planner)fix bug of char(255) toSql --- .../org/apache/doris/catalog/ScalarType.java | 4 ++-- .../ddl_p0/test_create_table_like_nereids.out | 6 +++++ .../test_create_table_like_nereids.groovy | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index 8b0ed24c926322..56c5d3eb4bc2d3 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -579,7 +579,7 @@ public static ScalarType createHllType() { public String toString() { if (type == PrimitiveType.CHAR) { if (isWildcardChar()) { - return "CHARACTER"; + return "CHARACTER(" + MAX_CHAR_LENGTH + ")"; } return "CHAR(" + len + ")"; } else if (type == PrimitiveType.DECIMALV2) { @@ -617,7 +617,7 @@ public String toSql(int depth) { switch (type) { case CHAR: if (isWildcardChar()) { - stringBuilder.append("CHARACTER"); + stringBuilder.append("CHARACTER").append("(").append(MAX_CHAR_LENGTH).append(")"); } else if (Strings.isNullOrEmpty(lenStr)) { stringBuilder.append("CHAR").append("(").append(len).append(")"); } else { diff --git a/regression-test/data/ddl_p0/test_create_table_like_nereids.out b/regression-test/data/ddl_p0/test_create_table_like_nereids.out index 4ecbecb1505623..137a4aa9466b4e 100644 --- a/regression-test/data/ddl_p0/test_create_table_like_nereids.out +++ b/regression-test/data/ddl_p0/test_create_table_like_nereids.out @@ -18,3 +18,9 @@ 6 \N 6 6 7 1 +-- !test_char_255 -- +0 + +-- !select -- +123 abcdddddd + diff --git a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy index d9d59b50ed50cc..b590b111722476 100644 --- a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy +++ b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy @@ -74,4 +74,28 @@ suite("test_create_table_like_nereids") { sql "drop table if exists table_like_with_partial_roll_up_exists" sql """CREATE TABLE if not exists table_like_with_partial_roll_up_exists LIKE mal_test_create_table_like with rollup (ru1);""" + + sql "drop table if exists test_create_table_like_char_255" + sql """ + CREATE TABLE test_create_table_like_char_255 + ( + `id` INT NOT NULL, + `name` CHAR(255) + ) + UNIQUE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS AUTO + PROPERTIES ( + "replication_num" = "3", + "light_schema_change" = "true" + ); + """ + sql "drop table if exists new_char_255" + qt_test_char_255 """ + create table new_char_255 like test_create_table_like_char_255; + """ + def res1 = sql "show create table new_char_255" + mustContain(res1[0][1], "CHARACTER(255)") + + sql "insert into new_char_255 values(123,'abcdddddd')" + qt_select "select * from new_char_255" } \ No newline at end of file From 615d1989777b85b074c9ebad5ffcca5811c40b85 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 8 Jul 2024 15:14:51 +0800 Subject: [PATCH 2/2] [Fix](planner)fix bug of char(255) toSql --- .../java/org/apache/doris/catalog/CreateFunctionTest.java | 2 +- .../schema_change_modify_mv_column_type.out | 4 ++-- .../suites/ddl_p0/test_create_table_like_nereids.groovy | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java index ba0acf1f8dedb0..32efc94bf71856 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java @@ -295,7 +295,7 @@ public void testCreateGlobalFunction() throws Exception { queryStr = "select to_char(k1, 4) from db2.tbl1;"; Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS CHARACTER)")); + "CAST(`k1` AS CHARACTER(255))")); } private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception { diff --git a/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out b/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out index 4e6f3c7a5eb7be..1cf151dc70c8bf 100644 --- a/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out +++ b/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out @@ -34,7 +34,7 @@ mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N tru mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` - mv_c_char CHARACTER CHARACTER Yes false \N NONE true `c_char` + mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` mv_c_string TEXT TEXT Yes false \N NONE true `c_string` @@ -97,7 +97,7 @@ mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N tru mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` - mv_c_char CHARACTER CHARACTER Yes false \N NONE true `c_char` + mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` mv_c_string TEXT TEXT Yes false \N NONE true `c_string` diff --git a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy index b590b111722476..9f06f049ce64d6 100644 --- a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy +++ b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy @@ -85,7 +85,7 @@ suite("test_create_table_like_nereids") { UNIQUE KEY(`id`) DISTRIBUTED BY HASH(`id`) BUCKETS AUTO PROPERTIES ( - "replication_num" = "3", + "replication_num" = "1", "light_schema_change" = "true" ); """