This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ac6cefa10ab8b3a50e6d84eaf210b2b267052a16
Author: abmdocrt <[email protected]>
AuthorDate: Mon Apr 8 17:08:08 2024 +0800

    [Fix](schema change) Fix schema change fault when add complex type column 
(#31824)
    
    Problem: An error is encountered when executing a schema change on a unique 
table to add a column with a complex type, such as bitmap, as documented in 
https://github.com/apache/doris/issues/31365
    
    Reason: The error arises because the schema change logic erroneously 
applies an aggregation check for new columns across all table types, demanding 
an explicit aggregation type declaration. However, unique and duplicate tables 
inherently assume default aggregation types for newly added columns, leading to 
this misstep.
    
    Solution: The schema change process for introducing new columns needs to 
distinguish between table types accurately. For unique and duplicate tables, it 
should automatically assign the appropriate aggregation type, which, for the 
purpose of smooth integration with subsequent processes, should be set to NONE.
---
 .../main/java/org/apache/doris/analysis/AddColumnClause.java |  4 ++++
 .../src/main/java/org/apache/doris/analysis/ColumnDef.java   | 12 ++++++++++--
 .../java/org/apache/doris/analysis/ModifyColumnClause.java   |  4 ++++
 .../schema_change_p0/test_schema_change_duplicate.groovy     |  7 +++++++
 .../suites/schema_change_p0/test_schema_change_unique.groovy |  8 ++++++++
 .../schema_change_p0/test_schema_change_unique_mow.groovy    |  7 +++++++
 6 files changed, 40 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AddColumnClause.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AddColumnClause.java
index 2d472cd5495..aa8e189b104 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AddColumnClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AddColumnClause.java
@@ -80,7 +80,11 @@ public class AddColumnClause extends AlterTableClause {
                     && columnDef.getAggregateType() == null) {
                 columnDef.setIsKey(true);
             }
+            if (table instanceof OlapTable) {
+                columnDef.setKeysType(((OlapTable) table).getKeysType());
+            }
         }
+
         columnDef.analyze(true);
         if (colPos != null) {
             colPos.analyze();
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 990035bbecf..559e6159916 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
@@ -22,6 +22,7 @@ package org.apache.doris.analysis;
 
 import org.apache.doris.catalog.AggregateType;
 import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.KeysType;
 import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.catalog.Type;
@@ -176,6 +177,7 @@ public class ColumnDef {
     private boolean isAllowNull;
     private boolean isAutoInc;
     private long autoIncInitValue;
+    private KeysType keysType;
     private DefaultValue defaultValue;
     private String comment;
     private boolean visible;
@@ -278,6 +280,10 @@ public class ColumnDef {
         this.isKey = isKey;
     }
 
+    public void setKeysType(KeysType keysType) {
+        this.keysType = keysType;
+    }
+
     public TypeDef getTypeDef() {
         return typeDef;
     }
@@ -318,8 +324,10 @@ public class ColumnDef {
             if (isKey) {
                 throw new AnalysisException("Key column can not set complex 
type:" + name);
             }
-            if (aggregateType == null) {
-                throw new AnalysisException("complex type have to use 
aggregate function: " + name);
+            if (keysType == null || keysType == KeysType.AGG_KEYS) {
+                if (aggregateType == null) {
+                    throw new AnalysisException("complex type have to use 
aggregate function: " + name);
+                }
             }
             isAllowNull = false;
         }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyColumnClause.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyColumnClause.java
index 5477614006b..49f5447163d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyColumnClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyColumnClause.java
@@ -75,7 +75,11 @@ public class ModifyColumnClause extends AlterTableClause {
                     && columnDef.getAggregateType() == null) {
                 columnDef.setIsKey(true);
             }
+            if (table instanceof OlapTable) {
+                columnDef.setKeysType(((OlapTable) table).getKeysType());
+            }
         }
+
         columnDef.analyze(true);
         if (colPos != null) {
             colPos.analyze();
diff --git 
a/regression-test/suites/schema_change_p0/test_schema_change_duplicate.groovy 
b/regression-test/suites/schema_change_p0/test_schema_change_duplicate.groovy
index ea88208597d..19e78ac05ba 100644
--- 
a/regression-test/suites/schema_change_p0/test_schema_change_duplicate.groovy
+++ 
b/regression-test/suites/schema_change_p0/test_schema_change_duplicate.groovy
@@ -202,6 +202,13 @@ suite("test_schema_change_duplicate", "p0") {
     sql """ insert into ${tableName3} values (10002, 2, 3, 4, 5, 6.6, 1.7, 8.8,
     'a', 'b', 'c', '2021-10-30', '2021-10-30 00:00:00', 10086) """
 
+    sql """ alter table ${tableName3} drop column v14 """
+    
+    sql """ alter table ${tableName3} add column v14 bitmap after k13 """
+
+    sql """ insert into ${tableName3} values (10002, 2, 3, 4, 5, 6.6, 1.7, 8.8,
+    'a', 'b', 'c', '2021-10-30', '2021-10-30 00:00:00', to_bitmap(243)) """
+
     sql """ alter table ${tableName3} drop column v14 """
 
     List<List<Object>> result  = sql """ select * from ${tableName3} """
diff --git 
a/regression-test/suites/schema_change_p0/test_schema_change_unique.groovy 
b/regression-test/suites/schema_change_p0/test_schema_change_unique.groovy
index 8f10451c076..66e91a4e4c3 100644
--- a/regression-test/suites/schema_change_p0/test_schema_change_unique.groovy
+++ b/regression-test/suites/schema_change_p0/test_schema_change_unique.groovy
@@ -204,6 +204,14 @@ suite("test_schema_change_unique", "p0") {
 
     sql """ alter table ${tableName3} drop column v14 """
 
+    sql """ alter table ${tableName3} add column v14 bitmap after k13 """
+
+    sql """ insert into ${tableName3} values (10002, 2, 3, 4, 5, 6.6, 1.7, 8.8,
+    'a', 'b', 'c', '2021-10-30', '2021-10-30 00:00:00', to_bitmap(243)) """
+
+    sql """ alter table ${tableName3} drop column v14 """
+
+
     List<List<Object>> result  = sql """ select * from ${tableName3} """
     for (row : result) {
         assertEquals(2, row[1]);
diff --git 
a/regression-test/suites/schema_change_p0/test_schema_change_unique_mow.groovy 
b/regression-test/suites/schema_change_p0/test_schema_change_unique_mow.groovy
index a4e552044d6..ad4a19d8d94 100644
--- 
a/regression-test/suites/schema_change_p0/test_schema_change_unique_mow.groovy
+++ 
b/regression-test/suites/schema_change_p0/test_schema_change_unique_mow.groovy
@@ -205,6 +205,13 @@ suite("test_schema_change_unique_mow", "p0") {
 
     sql """ alter table ${tableName3} drop column v14 """
 
+    sql """ alter table ${tableName3} add column v14 bitmap after k13 """
+
+    sql """ insert into ${tableName3} values (10002, 2, 3, 4, 5, 6.6, 1.7, 8.8,
+    'a', 'b', 'c', '2021-10-30', '2021-10-30 00:00:00', to_bitmap(243)) """
+
+    sql """ alter table ${tableName3} drop column v14 """
+
     List<List<Object>> result  = sql """ select * from ${tableName3} """
     for (row : result) {
         assertEquals(2, row[1]);


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

Reply via email to