This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 38f928391a4 [pick3.0][improve](schema) add column comment length limit
(#50344)
38f928391a4 is described below
commit 38f928391a46ed664faa37d46b93f7411a90f9f4
Author: camby <[email protected]>
AuthorDate: Wed Jun 11 10:41:36 2025 +0800
[pick3.0][improve](schema) add column comment length limit (#50344)
### What problem does this PR solve?
pick https://github.com/apache/doris/pull/49989
https://github.com/apache/doris/pull/50264 to branch-3.0
---
.../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 | 14 ++-
.../data/alter_p0/test_alter_column_comment.out | Bin 0 -> 635 bytes
.../alter_p0/test_alter_column_comment.groovy | 105 +++++++++++++++++++++
8 files changed, 134 insertions(+), 3 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 1833e3d009e..6bd3ce31064 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
@@ -1700,6 +1700,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 45465581907..966bc2dc18a 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
@@ -370,6 +370,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 94a82a422b8..2158bcacc9e 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 fbbd670c9df..c2906471111 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
@@ -101,6 +101,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 184b6d2fa55..239e3c0f32a 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
@@ -232,6 +232,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 a20037e541d..4a7def9ce16 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
@@ -891,7 +891,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) {
@@ -952,7 +957,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..b86f5718272
--- /dev/null
+++ b/regression-test/suites/alter_p0/test_alter_column_comment.groovy
@@ -0,0 +1,105 @@
+// 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', 'nonConcurrent') {
+ def tbl = 'test_alter_column_comment_tbl'
+ def cmt =
'0123456789012345678901234567890123456789012345678901234567890123456789'
+
+ 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 column_comment_length_limit
+ sql """ ADMIN SET FRONTEND CONFIG ("column_comment_length_limit" = "-1");
"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]