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 4a8df535537e8eab8fa2ad54934a185e17d4e660
Author: Pxl <pxl...@qq.com>
AuthorDate: Wed May 15 10:25:22 2024 +0800

    [Chore](rollup) check duplicate column name when create table with rollup 
(#34827)
    
    check duplicate column name when create table with rollup
---
 .../trees/plans/commands/info/CreateTableInfo.java |  4 ++++
 .../plans/commands/info/RollupDefinition.java      | 14 ++++++++++++-
 .../test_mv_useless/test_dup_mv_useless.groovy     | 23 ++++++++++++++++++++++
 .../suites/nereids_p0/create_table/ddl/table.sql   |  2 +-
 4 files changed, 41 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
index a4cf08efe74..585d1da0b10 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
@@ -459,6 +459,10 @@ public class CreateTableInfo {
                     }
                 }
             }
+
+            for (RollupDefinition rollup : rollups) {
+                rollup.validate();
+            }
         } else {
             // mysql, broker and hive do not need key desc
             if (keysType != null) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/RollupDefinition.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/RollupDefinition.java
index 6c3857279f5..b01e380e904 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/RollupDefinition.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/RollupDefinition.java
@@ -18,12 +18,15 @@
 package org.apache.doris.nereids.trees.plans.commands.info;
 
 import org.apache.doris.analysis.AddRollupClause;
+import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.util.Utils;
 
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * rollup definition
@@ -41,7 +44,16 @@ public class RollupDefinition {
         this.properties = Maps.newHashMap(properties);
     }
 
-    public void validate() {
+    /**
+     * check rollup validity
+     */
+    public void validate() throws AnalysisException {
+        Set<String> colSet = Sets.newHashSet();
+        for (String col : cols) {
+            if (!colSet.add(col)) {
+                throw new AnalysisException("rollup has duplicate column name 
" + col);
+            }
+        }
     }
 
     public AddRollupClause translateToCatalogStyle() {
diff --git 
a/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy 
b/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy
index 7640b6e1806..d91cafbe93d 100644
--- a/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy
+++ b/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy
@@ -48,4 +48,27 @@ suite ("test_dup_mv_useless") {
     createMV("create materialized view k1_k2_u21 as select k2,k1 from 
${testTable} group by k2,k1 order by k2,k1;")
     createMV("create materialized view k1_k2_sumk3 as select k1,k2,sum(k3) 
from ${testTable} group by k1,k2;")
     sql "insert into ${testTable} select 4,4,4;"
+
+    test {
+        sql """
+        create table test_rollup (
+            `id` int not null,
+            `kbool` boolean not null,
+            `ktint` tinyint(4) not null,
+            `ksint` smallint(6) not null,
+            `kint` int(11) not null,
+            `kbint` bigint(20) not null,
+            `klint` largeint(40) not null
+        ) engine=OLAP
+        duplicate key(id, kbool, ktint)
+        distributed by random buckets auto
+        rollup (
+            r1 (id, ktint, kbool, ktint, kbint) duplicate key(id)
+        )
+        properties (
+        "replication_num"="1"
+        );
+        """
+        exception "duplicate column name"
+    }
 }
diff --git a/regression-test/suites/nereids_p0/create_table/ddl/table.sql 
b/regression-test/suites/nereids_p0/create_table/ddl/table.sql
index bcac1168b73..c1f24407178 100644
--- a/regression-test/suites/nereids_p0/create_table/ddl/table.sql
+++ b/regression-test/suites/nereids_p0/create_table/ddl/table.sql
@@ -238,7 +238,7 @@ create table test_rollup (
 duplicate key(id, kbool, ktint)
 distributed by random buckets auto
 rollup (
-    r1 (id, ktint, kbool, ktint, kbint) duplicate key(id)
+    r1 (id, ktint, kbool, kbint) duplicate key(id)
 )
 properties (
    "replication_num"="1"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to