This is an automated email from the ASF dual-hosted git repository. cambyzju pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 028717935ea [improve](schema) add column comment length limit (#49989) 028717935ea is described below commit 028717935ea782db0b8befc2d049e88313cb28be Author: camby <camby...@tencent.com> AuthorDate: Thu Apr 17 21:08:06 2025 +0800 [improve](schema) add column comment length limit (#49989) --- .../main/java/org/apache/doris/common/Config.java | 6 ++ .../java/org/apache/doris/analysis/ColumnDef.java | 1 + .../java/org/apache/doris/catalog/SchemaTable.java | 2 +- .../java/org/apache/doris/common/FeNameFormat.java | 8 ++ .../plans/commands/info/ColumnDefinition.java | 1 + .../apache/doris/service/FrontendServiceImpl.java | 7 +- .../data/alter_p0/test_alter_column_comment.out | Bin 0 -> 635 bytes .../alter_p0/test_alter_column_comment.groovy | 107 +++++++++++++++++++++ 8 files changed, 130 insertions(+), 2 deletions(-) diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java index b7bcad16e27..9aac3378b7d 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java +++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java @@ -1768,6 +1768,12 @@ public class Config extends ConfigBase { @ConfField(mutable = true, masterOnly = true) public static int table_name_length_limit = 64; + @ConfField(mutable = true, description = { + "用于限制列注释长度;如果存量的列注释超长,则显示时进行截断", + "Used to limit the length of column comment; " + + "If the existing column comment is too long, it will be truncated when displayed."}) + public static int column_comment_length_limit = -1; + /* * The job scheduling interval of the schema change handler. * The user should not set this parameter. diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java index 404b0060b94..494052b764f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java @@ -376,6 +376,7 @@ public class ColumnDef { throw new AnalysisException("No column name or column type in column definition."); } FeNameFormat.checkColumnName(name); + FeNameFormat.checkColumnCommentLength(comment); typeDef.analyze(null); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java index e358f9566f0..13c44f2fed8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java @@ -183,7 +183,7 @@ public class SchemaTable extends Table { .column("COLUMN_KEY", ScalarType.createVarchar(3)) .column("EXTRA", ScalarType.createVarchar(27)) .column("PRIVILEGES", ScalarType.createVarchar(80)) - .column("COLUMN_COMMENT", ScalarType.createVarchar(255)) + .column("COLUMN_COMMENT", ScalarType.createVarchar(1024)) .column("COLUMN_SIZE", ScalarType.createType(PrimitiveType.BIGINT)) .column("DECIMAL_DIGITS", ScalarType.createType(PrimitiveType.BIGINT)) .column("GENERATION_EXPRESSION", ScalarType.createVarchar(64)) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java b/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java index 4a174913a72..49621f1331a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java @@ -108,6 +108,14 @@ public class FeNameFormat { } } + public static void checkColumnCommentLength(String comment) throws AnalysisException { + if (!Strings.isNullOrEmpty(comment) && Config.column_comment_length_limit > 0 + && comment.length() > Config.column_comment_length_limit) { + throw new AnalysisException("Column comment is too long " + comment.length() + ", max length is " + + Config.column_comment_length_limit); + } + } + public static void checkLabel(String label) throws AnalysisException { if (Strings.isNullOrEmpty(label) || !label.matches(getLabelRegex())) { throw new AnalysisException("Label format error. regex: " + getLabelRegex() + ", label: " + label); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java index 2b66ad1e768..62cc32f2016 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java @@ -287,6 +287,7 @@ public class ColumnDefinition { KeysType keysType) { try { FeNameFormat.checkColumnName(name); + FeNameFormat.checkColumnCommentLength(comment); } catch (Exception e) { throw new AnalysisException(e.getMessage(), e); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java index c082abed538..a2f5b0b5e43 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java +++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java @@ -887,7 +887,12 @@ public class FrontendServiceImpl implements FrontendService.Iface { final TColumnDef colDef = new TColumnDef(desc); final String comment = column.getComment(); if (comment != null) { - colDef.setComment(comment); + if (Config.column_comment_length_limit > 0 + && comment.length() > Config.column_comment_length_limit) { + colDef.setComment(comment.substring(0, Config.column_comment_length_limit)); + } else { + colDef.setComment(comment); + } } if (column.isKey()) { if (table instanceof OlapTable) { diff --git a/regression-test/data/alter_p0/test_alter_column_comment.out b/regression-test/data/alter_p0/test_alter_column_comment.out new file mode 100644 index 00000000000..7ec5347dc68 Binary files /dev/null and b/regression-test/data/alter_p0/test_alter_column_comment.out differ diff --git a/regression-test/suites/alter_p0/test_alter_column_comment.groovy b/regression-test/suites/alter_p0/test_alter_column_comment.groovy new file mode 100644 index 00000000000..278a27fdaa8 --- /dev/null +++ b/regression-test/suites/alter_p0/test_alter_column_comment.groovy @@ -0,0 +1,107 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite('test_alter_column_comment') { + def tbl = 'test_alter_column_comment_tbl' + def cmt = '0123456789012345678901234567890123456789012345678901234567890123456789' + + def config_row = sql """ ADMIN SHOW FRONTEND CONFIG LIKE 'column_comment_length_limit'; """ + String old_limit = config_row[0][1] + sql "ADMIN SET FRONTEND CONFIG ('column_comment_length_limit' = '64')" + + sql "DROP TABLE IF EXISTS ${tbl} FORCE" + + // create table with too long column comment + test { + sql """ + CREATE TABLE ${tbl} ( + `k1` BIGINT NOT NULL comment "${cmt}", + `v1` BIGINT NULL comment "${cmt}", + `v2` INT NULL + ) ENGINE=OLAP + UNIQUE KEY(`k1`) + DISTRIBUTED BY HASH(`k1`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + exception("Column comment is too long"); + } + + // create table for following tests + sql """ + CREATE TABLE ${tbl} ( + `k1` BIGINT NOT NULL, + `v1` BIGINT NULL, + `v2` INT NULL + ) ENGINE=OLAP + UNIQUE KEY(`k1`) + DISTRIBUTED BY HASH(`k1`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ + INSERT INTO ${tbl} VALUES (1,1,1),(2,2,2),(3,3,3) + """ + sql """ SYNC """ + + // alter add column with too long column comment + test { + sql """ + ALTER TABLE ${tbl} add column v3 int comment "${cmt}" + """ + exception("Column comment is too long"); + } + + // alter modify column with too long column comment + test { + sql """ + ALTER TABLE ${tbl} modify column v2 int comment "${cmt}" + """ + exception("Column comment is too long"); + } + + // alter add column with short column comment + sql """ + ALTER TABLE ${tbl} add column v3 int comment "short_comment" + """ + waitForSchemaChangeDone { + sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tbl}' ORDER BY createtime DESC LIMIT 1 """ + time 600 + } + + // alter modify column with short column comment + sql """ + ALTER TABLE ${tbl} modify column v2 int comment "short_comment_v2" + """ + waitForSchemaChangeDone { + sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tbl}' ORDER BY createtime DESC LIMIT 1 """ + time 600 + } + + // Check table structure after ALTER TABLE + qt_select """ SELECT TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_COMMENT FROM information_schema.columns where TABLE_SCHEMA='${context.dbName}' and table_name='${tbl}' order by TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME """ + + // use a smaller config, column comment should be truncated + sql "ADMIN SET FRONTEND CONFIG ('column_comment_length_limit' = '4')" + qt_select1 """ SELECT TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_COMMENT FROM information_schema.columns where TABLE_SCHEMA='${context.dbName}' and table_name='${tbl}' order by TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME """ + + sql "DROP TABLE IF EXISTS ${tbl} FORCE" + // restore old_limit to old_value + sql """ ADMIN SET FRONTEND CONFIG ("column_comment_length_limit" = "${old_limit}"); """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org