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 7bf370597dd [fix](schema-change) Nested types should only support 
enlarging varchar length with light schema change (#49452) (#49592)
7bf370597dd is described below

commit 7bf370597dd75b4ee0a42e4977bb183dfda25d7e
Author: Siyang Tang <[email protected]>
AuthorDate: Fri Mar 28 21:11:21 2025 +0800

    [fix](schema-change) Nested types should only support enlarging varchar 
length with light schema change (#49452) (#49592)
    
    ### What problem does this PR solve?
    
    cherry-pick: #49452
    
    Problem Summary:
    
    Currently nested types only support light schema change for internal
    fields, for string types, only varchar can do light schema change.
---
 .../java/org/apache/doris/catalog/ColumnType.java  |  9 +++-
 .../test_type_length_change.groovy                 |  7 ++-
 .../test_varchar_sc_in_complex.groovy              | 55 ++++++++++++++++++++++
 3 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java
index 302e53ec457..6227bea2b1b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java
@@ -100,6 +100,7 @@ public abstract class ColumnType {
         
schemaChangeMatrix[PrimitiveType.VARCHAR.ordinal()][PrimitiveType.DATEV2.ordinal()]
 = true;
         
schemaChangeMatrix[PrimitiveType.VARCHAR.ordinal()][PrimitiveType.STRING.ordinal()]
 = true;
         
schemaChangeMatrix[PrimitiveType.VARCHAR.ordinal()][PrimitiveType.JSONB.ordinal()]
 = true;
+        // could not change varchar to char cuz varchar max length is larger 
than char
 
         
schemaChangeMatrix[PrimitiveType.STRING.ordinal()][PrimitiveType.JSONB.ordinal()]
 = true;
 
@@ -192,7 +193,10 @@ public abstract class ColumnType {
     // return true if the checkType and other are both char-type otherwise 
return false,
     // which used in checkSupportSchemaChangeForComplexType
     private static boolean checkSupportSchemaChangeForCharType(Type checkType, 
Type other) throws DdlException {
-        if (checkType.isStringType() && other.isStringType()) {
+        if (checkType.getPrimitiveType() == PrimitiveType.VARCHAR
+                && other.getPrimitiveType() == PrimitiveType.VARCHAR) {
+            // currently nested types only support light schema change for 
internal fields, for string types,
+            // only varchar can do light schema change
             checkForTypeLengthChange(checkType, other);
             return true;
         } else {
@@ -230,7 +234,8 @@ public abstract class ColumnType {
             // only support char-type schema change behavior for nested 
complex type
             // if nested is false, we do not check return value.
             if (nested && !checkSupportSchemaChangeForCharType(checkType, 
other)) {
-                throw new DdlException("Cannot change " + checkType.toSql() + 
" to " + other.toSql());
+                throw new DdlException(
+                        "Cannot change " + checkType.toSql() + " to " + 
other.toSql() + " in nested types");
             }
         }
     }
diff --git 
a/regression-test/suites/schema_change_p0/test_type_length_change.groovy 
b/regression-test/suites/schema_change_p0/test_type_length_change.groovy
index 3a071aabf5e..3fa18c3fe4c 100644
--- a/regression-test/suites/schema_change_p0/test_type_length_change.groovy
+++ b/regression-test/suites/schema_change_p0/test_type_length_change.groovy
@@ -25,7 +25,7 @@ suite("test_type_length_change", "p0") {
             c0 CHAR(5),
             c1 VARCHAR(5)
         ) DUPLICATE KEY (k)
-       DISTRIBUTED BY HASH(k) BUCKETS 1
+        DISTRIBUTED BY HASH(k) BUCKETS 1
         PROPERTIES ( "replication_allocation" = "tag.location.default: 1");
     """
 
@@ -75,4 +75,9 @@ suite("test_type_length_change", "p0") {
     sql """  INSERT INTO ${tableName} VALUES(4, "abcde", "abcde") """
     qt_master_sql """ SELECT * FROM ${tableName} ORDER BY k"""
     qt_master_sql """ DESC ${tableName} """
+
+    test {
+        sql """ ALTER TABLE ${tableName} MODIFY COLUMN c1 CHAR(10) """
+        exception "Can not change VARCHAR to CHAR"
+    }
 }
diff --git 
a/regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy 
b/regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy
index 584a422f2a7..1544c82068f 100644
--- a/regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy
+++ b/regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy
@@ -476,6 +476,61 @@ suite ("test_varchar_sc_in_complex") {
 //            """
 //        qt_sc_after " select * from there_level_nested_type order by c0; "
 
+        // case7. do not support enlarge char length in nested types
+        def tableName2 = "test_enlarge_char_length_nested"
+        sql """ DROP TABLE IF EXISTS ${tableName2} """
+        sql """
+            CREATE TABLE IF NOT EXISTS ${tableName2}
+            (
+                k BIGINT NOT NULL,
+                c1 ARRAY<CHAR(10)>,
+                c2 MAP<CHAR(10), CHAR(10)>,
+                c3 STRUCT<col:CHAR(10)>,
+                c4 ARRAY<VARCHAR(10)>,
+                c5 MAP<VARCHAR(10), VARCHAR(10)>,
+                c6 STRUCT<col:VARCHAR(10)>
+            ) DISTRIBUTED BY HASH(k) BUCKETS 1
+              PROPERTIES ( "replication_num" = "1", "light_schema_change" = 
"true" );
+        """
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c1 ARRAY<CHAR(20)> 
"""
+            exception "Cannot change char(10) to char(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c2 MAP<CHAR(20), 
CHAR(20)> """
+            exception "Cannot change char(10) to char(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c3 
STRUCT<col:CHAR(20)> """
+            exception "Cannot change char(10) to char(20) in nested types"
+        }
+
+        // case8. do not support convert from char to varchar and varchar to 
char in nested types
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c1 
ARRAY<VARCHAR(20)> """
+            exception "Cannot change char(10) to varchar(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c2 
MAP<VARCHAR(20), VARCHAR(20)> """
+            exception "Cannot change char(10) to varchar(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c3 
STRUCT<col:VARCHAR(20)> """
+            exception "Cannot change char(10) to varchar(20) in nested types"
+        }
+
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c4 ARRAY<CHAR(20)> 
"""
+            exception "Cannot change varchar(10) to char(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c5 MAP<CHAR(20), 
CHAR(20)> """
+            exception "Cannot change varchar(10) to char(20) in nested types"
+        }
+        test {
+            sql """ ALTER TABLE ${tableName2} MODIFY COLUMN c6 
STRUCT<col:CHAR(20)> """
+            exception "Cannot change varchar(10) to char(20) in nested types"
+        }
     } finally {
          try_sql("DROP TABLE IF EXISTS ${tableName}")
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to