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

yangzhg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 32f6dec  fix dup table don't schema schange (#6791)
32f6dec is described below

commit 32f6dec80fbe52b8e11a12e6d268e8cdaabfaf47
Author: shee <[email protected]>
AuthorDate: Wed Oct 13 11:37:39 2021 +0800

    fix dup table don't schema schange (#6791)
    
    Co-authored-by: qzsee <[email protected]>
---
 .../apache/doris/alter/SchemaChangeHandler.java    |  7 +++--
 .../org/apache/doris/alter/AlterJobV2Test.java     | 32 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
index 27bfa69..313ad47 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
@@ -1119,6 +1119,7 @@ public class SchemaChangeHandler extends AlterHandler {
         for (Long alterIndexId : indexSchemaMap.keySet()) {
             List<Column> originSchema = 
olapTable.getSchemaByIndexId(alterIndexId);
             List<Column> alterSchema = indexSchemaMap.get(alterIndexId);
+            Set<Column> needAlterColumns = Sets.newHashSet();
 
             // 0. check if unchanged
             boolean hasColumnChange = false;
@@ -1128,8 +1129,8 @@ public class SchemaChangeHandler extends AlterHandler {
                 for (int i = 0; i < alterSchema.size(); i++) {
                     Column alterColumn = alterSchema.get(i);
                     if (!alterColumn.equals(originSchema.get(i))) {
+                        needAlterColumns.add(alterColumn);
                         hasColumnChange = true;
-                        break;
                     }
                 }
             }
@@ -1220,7 +1221,7 @@ public class SchemaChangeHandler extends AlterHandler {
                     for (Column alterColumn : alterSchema) {
                         if (alterColumn.nameEquals(partitionCol.getName(), 
true)) {
                             // 2.1 partition column cannot be modified
-                            if (!alterColumn.equals(partitionCol)) {
+                            if (needAlterColumns.contains(alterColumn)) {
                                 throw new DdlException("Can not modify 
partition column["
                                         + partitionCol.getName() + "]. index["
                                         + 
olapTable.getIndexNameById(alterIndexId) + "]");
@@ -1249,7 +1250,7 @@ public class SchemaChangeHandler extends AlterHandler {
                     for (Column alterColumn : alterSchema) {
                         if (alterColumn.nameEquals(distributionCol.getName(), 
true)) {
                             // 3.1 distribution column cannot be modified
-                            if (!alterColumn.equals(distributionCol)) {
+                            if (needAlterColumns.contains(alterColumn)) {
                                 throw new DdlException("Can not modify 
distribution column["
                                         + distributionCol.getName() + "]. 
index["
                                         + 
olapTable.getIndexNameById(alterIndexId) + "]");
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/alter/AlterJobV2Test.java 
b/fe/fe-core/src/test/java/org/apache/doris/alter/AlterJobV2Test.java
index af7ae27..6a25b72 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/alter/AlterJobV2Test.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/alter/AlterJobV2Test.java
@@ -27,6 +27,7 @@ import org.apache.doris.catalog.OlapTable;
 import org.apache.doris.catalog.Table;
 import org.apache.doris.common.Config;
 import org.apache.doris.common.DdlException;
+import org.apache.doris.common.ExceptionChecker;
 import org.apache.doris.common.FeConstants;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.ShowExecutor;
@@ -79,6 +80,11 @@ public class AlterJobV2Test {
         Catalog.getCurrentCatalog().createTable(createTableStmt);
     }
 
+    private static void alterTable(String sql) throws Exception {
+        AlterTableStmt alterTableStmt = (AlterTableStmt) 
UtFrameUtils.parseAndAnalyzeStmt(sql, connectContext);
+        
Catalog.getCurrentCatalog().getAlterInstance().processAlterTable(alterTableStmt);
+    }
+
     @Test
     public void testSchemaChange() throws Exception {
         // 1. process a schema change job
@@ -185,4 +191,30 @@ public class AlterJobV2Test {
             Assert.assertTrue(e.getMessage().contains("Nothing is changed"));
         }
     }
+
+    @Test
+    public void testDupTableSchemaChange() throws Exception {
+
+        createTable("CREATE TABLE test.dup_table (\n" +
+                "  k1 bigint(20) NULL ,\n" +
+                "  k2 bigint(20) NULL ,\n" +
+                "  k3 bigint(20) NULL,\n" +
+                "  v1 bigint(20) NULL ,\n" +
+                "  v2 varchar(1) NULL,\n" +
+                "  v3 varchar(1) NULL \n" +
+                ") ENGINE=OLAP\n" +
+                "DUPLICATE KEY(k1, k2, k3)\n" +
+                "PARTITION BY RANGE(k1, v1)\n" +
+                "(PARTITION p1 VALUES LESS THAN (\"10\", \"10\"))\n" +
+                "DISTRIBUTED BY HASH(v1,k2) BUCKETS 10\n" +
+                "PROPERTIES (\n" +
+                "\"replication_num\" = \"1\"\n" +
+                ");");
+
+
+        alterTable("alter table test.dup_table add rollup r1(v1,v2,k2,k1);");
+        Map<Long, AlterJobV2> alterJobs = 
Catalog.getCurrentCatalog().getRollupHandler().getAlterJobsV2();
+        waitAlterJobDone(alterJobs);
+        ExceptionChecker.expectThrowsNoException(() -> alterTable("alter table 
test.dup_table modify column v2 varchar(2);"));
+    }
 }

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

Reply via email to