eldenmoon commented on code in PR #46639:
URL: https://github.com/apache/doris/pull/46639#discussion_r1908073766


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java:
##########
@@ -885,12 +880,10 @@ public void checkSchemaChangeAllowed(Column other) throws 
DdlException {
             }
         }
 
-        if ((getDataType() == PrimitiveType.VARCHAR && other.getDataType() == 
PrimitiveType.VARCHAR) || (
-                getDataType() == PrimitiveType.CHAR && other.getDataType() == 
PrimitiveType.VARCHAR) || (
-                getDataType() == PrimitiveType.CHAR && other.getDataType() == 
PrimitiveType.CHAR)) {
-            if (getStrLen() > other.getStrLen()) {
-                throw new DdlException("Cannot shorten string length");
-            }
+        // Nested types only support changing the order and increasing the 
length of the nested char type
+        // Char-type only support length growing
+        if (!type.isSupportSchemaChangeForCharType(other.type)) {

Review Comment:
   what about type is Array other.type is Int, the exception error message is 
not correct



##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -627,8 +627,9 @@ private boolean processModifyColumn(ModifyColumnClause 
alterClause, OlapTable ol
                 if (!col.equals(modColumn)) {
                     typeChanged = true;
                     // TODO:the case where columnPos is not empty has not been 
considered
-                    if (columnPos == null && col.getDataType() == 
PrimitiveType.VARCHAR
-                            && modColumn.getDataType() == 
PrimitiveType.VARCHAR) {
+                    if (columnPos == null && ((col.getDataType() == 
PrimitiveType.VARCHAR
+                            && modColumn.getDataType() == 
PrimitiveType.VARCHAR)
+                            || col.getDataType().isComplexType())) {

Review Comment:
   is this correct?what about col is struct and modColumn is array? this 
condiction will break the original rule



##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -627,8 +627,9 @@ private boolean processModifyColumn(ModifyColumnClause 
alterClause, OlapTable ol
                 if (!col.equals(modColumn)) {
                     typeChanged = true;
                     // TODO:the case where columnPos is not empty has not been 
considered
-                    if (columnPos == null && col.getDataType() == 
PrimitiveType.VARCHAR
-                            && modColumn.getDataType() == 
PrimitiveType.VARCHAR) {
+                    if (columnPos == null && ((col.getDataType() == 
PrimitiveType.VARCHAR
+                            && modColumn.getDataType() == 
PrimitiveType.VARCHAR)
+                            || col.getDataType().isComplexType())) {

Review Comment:
   maybe also use isSupportSchemaChangeForCharType



##########
regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy:
##########
@@ -0,0 +1,149 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+import java.util.concurrent.TimeUnit
+import org.awaitility.Awaitility
+
+suite ("test_varchar_sc_in_complex") {
+    def getJobState = { tableName ->
+         def jobStateResult = sql """  SHOW ALTER TABLE COLUMN WHERE 
IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """
+         return jobStateResult[0][9]
+    }
+
+    def tableName = "test_varchar_sc_in_complex"
+
+    try {
+
+        String backend_id;
+        def backendId_to_backendIP = [:]
+        def backendId_to_backendHttpPort = [:]
+        getBackendIpHttpPort(backendId_to_backendIP, 
backendId_to_backendHttpPort);
+
+        sql """ DROP TABLE IF EXISTS ${tableName} """
+        sql """
+                CREATE TABLE IF NOT EXISTS ${tableName} (
+                    `c0` LARGEINT NOT NULL,
+                    `c_a` ARRAY<VARCHAR(10)>,
+                    `c_m` MAP<VARCHAR(10),VARCHAR(10)>,
+                    `c_s` STRUCT<col:VARCHAR(10)>
+                ) DISTRIBUTED BY HASH(c0) BUCKETS 1
+                PROPERTIES ( "replication_num" = "1", "light_schema_change" = 
"true" )
+            """
+
+        sql """ insert into ${tableName} values
+                (0,['2025-01-01'], {'amory':'better'}, 
named_struct('col','commiter'));
+            """
+        sql """ insert into ${tableName} values
+                (1,['2025-01-02'], {'doris':'better'}, 
named_struct('col','amory'));
+            """
+        // this can be insert but with cut off the left string to 10
+        test {
+            sql """ insert into ${tableName} values
+                (11, ['2025-01-03-22-33'], 
{'doris111111111':'better2222222222'}, named_struct('col','amoryIsBetter'));
+            """
+            exception "Insert has filtered data in strict mode"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_a 
array<varchar(3)>
+                """
+            exception "Cannot shorten string length"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_m 
map<varchar(3),varchar(3)>
+                """
+            exception "Cannot shorten string length"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_s 
struct<col:varchar(3)>
+                """
+            exception "Cannot shorten string length"

Review Comment:
   add case alter modify c_a string to test schema change from array to string 
or vice versa



##########
regression-test/suites/schema_change_p0/test_varchar_sc_in_complex.groovy:
##########
@@ -0,0 +1,149 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+import java.util.concurrent.TimeUnit
+import org.awaitility.Awaitility
+
+suite ("test_varchar_sc_in_complex") {
+    def getJobState = { tableName ->
+         def jobStateResult = sql """  SHOW ALTER TABLE COLUMN WHERE 
IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """
+         return jobStateResult[0][9]
+    }
+
+    def tableName = "test_varchar_sc_in_complex"
+
+    try {
+
+        String backend_id;
+        def backendId_to_backendIP = [:]
+        def backendId_to_backendHttpPort = [:]
+        getBackendIpHttpPort(backendId_to_backendIP, 
backendId_to_backendHttpPort);
+
+        sql """ DROP TABLE IF EXISTS ${tableName} """
+        sql """
+                CREATE TABLE IF NOT EXISTS ${tableName} (
+                    `c0` LARGEINT NOT NULL,
+                    `c_a` ARRAY<VARCHAR(10)>,
+                    `c_m` MAP<VARCHAR(10),VARCHAR(10)>,
+                    `c_s` STRUCT<col:VARCHAR(10)>
+                ) DISTRIBUTED BY HASH(c0) BUCKETS 1
+                PROPERTIES ( "replication_num" = "1", "light_schema_change" = 
"true" )
+            """
+
+        sql """ insert into ${tableName} values
+                (0,['2025-01-01'], {'amory':'better'}, 
named_struct('col','commiter'));
+            """
+        sql """ insert into ${tableName} values
+                (1,['2025-01-02'], {'doris':'better'}, 
named_struct('col','amory'));
+            """
+        // this can be insert but with cut off the left string to 10
+        test {
+            sql """ insert into ${tableName} values
+                (11, ['2025-01-03-22-33'], 
{'doris111111111':'better2222222222'}, named_struct('col','amoryIsBetter'));
+            """
+            exception "Insert has filtered data in strict mode"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_a 
array<varchar(3)>
+                """
+            exception "Cannot shorten string length"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_m 
map<varchar(3),varchar(3)>
+                """
+            exception "Cannot shorten string length"
+        }
+
+        test {
+            sql """ alter table ${tableName} modify column c_s 
struct<col:varchar(3)>
+                """

Review Comment:
   add case alter modify c_s array<varchar(3)> to test schema change from 
struct to array or vice versa
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to