[Chore](rollup) check duplicate column name when create table with rollup (#34827)

check duplicate column name when create table with rollup
This commit is contained in:
Pxl
2024-05-15 10:25:22 +08:00
committed by yiguolei
parent 1e53a2a81d
commit 4a8df53553
4 changed files with 41 additions and 2 deletions

View File

@ -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) {

View File

@ -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() {

View File

@ -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"
}
}

View File

@ -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"