This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 914b6a77597 [cherry-pick](branch-2.0) pick "[Fix](schema change) Fix schema change fault when add complex type column (#31824)" (#37598) 914b6a77597 is described below commit 914b6a775970f617d3615d02b206fe7fa84d1d14 Author: abmdocrt <yukang.lian2...@gmail.com> AuthorDate: Sun Jul 14 00:50:40 2024 +0800 [cherry-pick](branch-2.0) pick "[Fix](schema change) Fix schema change fault when add complex type column (#31824)" (#37598) 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. pick #31824 ## Proposed changes Issue Number: close #xxx <!--Describe your changes.--> --- .../java/org/apache/doris/analysis/AddColumnClause.java | 4 ++++ .../src/main/java/org/apache/doris/analysis/ColumnDef.java | 13 +++++++++++-- .../java/org/apache/doris/analysis/ModifyColumnClause.java | 4 ++++ .../schema_change_p0/test_schema_change_duplicate.groovy | 7 +++++++ .../schema_change_p0/test_schema_change_unique.groovy | 8 ++++++++ .../schema_change_p0/test_schema_change_unique_mow.groovy | 7 +++++++ 6 files changed, 41 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 2cd6b1e2870..da911c989af 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; @@ -178,6 +179,8 @@ public class ColumnDef { private boolean isKey; private boolean isAllowNull; private boolean isAutoInc; + private long autoIncInitValue; + private KeysType keysType; private DefaultValue defaultValue; private String comment; private boolean visible; @@ -290,6 +293,10 @@ public class ColumnDef { this.isKey = isKey; } + public void setKeysType(KeysType keysType) { + this.keysType = keysType; + } + public TypeDef getTypeDef() { return typeDef; } @@ -326,8 +333,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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org