From 71ce3618ab6f360ec7c8c1717c7b04a4c43cad91 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:31:03 +0000 Subject: [PATCH] [BugFix] Reject table create request with time type in complex type (backport #54601) (#54701) Co-authored-by: zhangqiang --- .../java/com/starrocks/common/util/Util.java | 49 ++++++++++++++-- .../starrocks/server/OlapTableFactory.java | 1 + .../R/test_create_table_with_time | 57 +++++++++++++++++++ .../T/test_create_table_with_time | 49 ++++++++++++++++ 4 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 test/sql/test_create_table/R/test_create_table_with_time create mode 100644 test/sql/test_create_table/T/test_create_table_with_time diff --git a/fe/fe-core/src/main/java/com/starrocks/common/util/Util.java b/fe/fe-core/src/main/java/com/starrocks/common/util/Util.java index 655b568a86b11..150d444bae134 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/util/Util.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/util/Util.java @@ -36,8 +36,13 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; +import com.starrocks.catalog.ArrayType; import com.starrocks.catalog.Column; +import com.starrocks.catalog.MapType; import com.starrocks.catalog.PrimitiveType; +import com.starrocks.catalog.ScalarType; +import com.starrocks.catalog.StructField; +import com.starrocks.catalog.StructType; import com.starrocks.catalog.Type; import com.starrocks.common.AnalysisException; import com.starrocks.common.TimeoutException; @@ -241,22 +246,22 @@ public static List shellSplit(CharSequence string) { return tokens; } - private static String columnHashString(Column column) { - Type type = column.getType(); + private static String columnHashString(Type type) { if (type.isScalarType()) { PrimitiveType primitiveType = type.getPrimitiveType(); switch (primitiveType) { case CHAR: case VARCHAR: return String.format( - TYPE_STRING_MAP.get(primitiveType), column.getStrLen()); + TYPE_STRING_MAP.get(primitiveType), ((ScalarType) type).getLength()); case DECIMALV2: case DECIMAL32: case DECIMAL64: case DECIMAL128: return String.format( - TYPE_STRING_MAP.get(primitiveType), column.getPrecision(), - column.getScale()); + TYPE_STRING_MAP.get(primitiveType), + ((ScalarType) type).getScalarPrecision(), + ((ScalarType) type).getScalarScale()); default: return TYPE_STRING_MAP.get(primitiveType); } @@ -273,7 +278,7 @@ public static int schemaHash(int schemaVersion, List columns, Set columns) { + for (Column column : columns) { + Type type = column.getType(); + if (!checkTypeSupported(type)) { + throw new SemanticException("Type:%s of column:%s does not support", + column.getType().toString(), column.getName()); + } + } + return true; + } + // get response body as a string from the given url. // "encodedAuthInfo", the base64 encoded auth info. like: // Base64.encodeBase64String("user:passwd".getBytes()); diff --git a/fe/fe-core/src/main/java/com/starrocks/server/OlapTableFactory.java b/fe/fe-core/src/main/java/com/starrocks/server/OlapTableFactory.java index 4f71460adc9a3..a2dbd5ba84ec5 100644 --- a/fe/fe-core/src/main/java/com/starrocks/server/OlapTableFactory.java +++ b/fe/fe-core/src/main/java/com/starrocks/server/OlapTableFactory.java @@ -588,6 +588,7 @@ public Table createTable(LocalMetastore metastore, Database db, CreateTableStmt } catch (AnalysisException e) { throw new DdlException(e.getMessage()); } + Util.checkColumnSupported(baseSchema); int schemaHash = Util.schemaHash(schemaVersion, baseSchema, bfColumns, bfFpp); if (stmt.getSortKeys() != null) { diff --git a/test/sql/test_create_table/R/test_create_table_with_time b/test/sql/test_create_table/R/test_create_table_with_time new file mode 100644 index 0000000000000..6d1bd9295f83e --- /dev/null +++ b/test/sql/test_create_table/R/test_create_table_with_time @@ -0,0 +1,57 @@ +-- name: test_create_table_with_time +CREATE TABLE dup_test ( + id bigint, + city varchar(100) not null, + time TIME not null +) +DUPLICATE KEY(id) +PARTITION BY (city) +DISTRIBUTED BY HASH(`id`) +PROPERTIES ( +"replication_num" = "1" +); +-- result: +E: (1064, 'Getting analyzing error. Detail message: Type:TIME of column:time does not support.') +-- !result +CREATE TABLE dup_test ( + id bigint, + city varchar(100) not null, + time array