Skip to content

Commit 274e4d7

Browse files
committed
fix
Signed-off-by: gengjun-git <gengjun@starrocks.com>
1 parent 4451f5f commit 274e4d7

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

fe/fe-core/src/main/java/com/starrocks/planner/OlapTableSink.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,12 @@ private static DistributionInfo setDistributedColumns(TOlapTablePartitionParam p
859859
throw new StarRocksException("different distribute types in two different partitions, type1="
860860
+ selectedDistInfo.getType() + ", type2=" + distInfo.getType());
861861
}
862+
List<String> selectedDistColumns = getDistColumns(selectedDistInfo, table);
863+
List<String> currentDistColumns = getDistColumns(distInfo, table);
864+
if (!selectedDistColumns.equals(currentDistColumns)) {
865+
throw new StarRocksException("different distribute columns in two different partitions, columns1="
866+
+ selectedDistColumns + ", columns2=" + currentDistColumns);
867+
}
862868
}
863869
return selectedDistInfo;
864870
}

fe/fe-core/src/test/java/com/starrocks/planner/OlapTableSinkTest2.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
package com.starrocks.planner;
1616

17+
import com.google.common.collect.Lists;
18+
import com.starrocks.catalog.Column;
1719
import com.starrocks.catalog.Database;
20+
import com.starrocks.catalog.DistributionInfo;
21+
import com.starrocks.catalog.HashDistributionInfo;
1822
import com.starrocks.catalog.OlapTable;
1923
import com.starrocks.catalog.Partition;
2024
import com.starrocks.catalog.PartitionInfo;
@@ -26,6 +30,7 @@
2630
import com.starrocks.thrift.TOlapTablePartition;
2731
import com.starrocks.thrift.TOlapTablePartitionParam;
2832
import com.starrocks.thrift.TWriteQuorumType;
33+
import com.starrocks.type.IntegerType;
2934
import com.starrocks.utframe.StarRocksAssert;
3035
import com.starrocks.utframe.UtFrameUtils;
3136
import mockit.Mock;
@@ -34,6 +39,9 @@
3439
import org.junit.jupiter.api.BeforeAll;
3540
import org.junit.jupiter.api.Test;
3641

42+
import java.util.List;
43+
import java.util.stream.Collectors;
44+
3745
public class OlapTableSinkTest2 {
3846
private static StarRocksAssert starRocksAssert;
3947
private static ConnectContext connectContext;
@@ -47,6 +55,22 @@ public static void beforeClass() throws Exception {
4755
starRocksAssert = new StarRocksAssert(connectContext);
4856
starRocksAssert.withDatabase("db2");
4957
starRocksAssert.withTable(createTblStmtStr);
58+
59+
String createRangeTableStmt = "create table db2.tbl_range(k1 int, k2 int, v1 int) " +
60+
"DUPLICATE KEY(k1) " +
61+
"PARTITION BY RANGE(k1) (" +
62+
" PARTITION p1 VALUES LESS THAN ('10')," +
63+
" PARTITION p2 VALUES LESS THAN ('20')" +
64+
") DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES('replication_num' = '1');";
65+
starRocksAssert.withTable(createRangeTableStmt);
66+
67+
String createListTableStmt = "create table db2.tbl_list(k1 int, k2 int, v1 int) " +
68+
"DUPLICATE KEY(k1) " +
69+
"PARTITION BY LIST(k1) (" +
70+
" PARTITION p1 VALUES IN ('1', '2', '3')," +
71+
" PARTITION p2 VALUES IN ('4', '5', '6')" +
72+
") DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES('replication_num' = '1');";
73+
starRocksAssert.withTable(createListTableStmt);
5074
}
5175

5276
@Test
@@ -79,4 +103,69 @@ public int getQuorumNum(long partitionId, TWriteQuorumType writeQuorum) {
79103
}
80104
Assertions.fail("must throw UserException");
81105
}
106+
107+
@Test
108+
public void testRangePartitionWithDifferentDistributionColumns() {
109+
Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb("db2");
110+
OlapTable olapTable = (OlapTable) GlobalStateMgr.getCurrentState().getLocalMetastore()
111+
.getTable(db.getFullName(), "tbl_range");
112+
113+
// Get two partitions
114+
Partition p1 = olapTable.getPartition("p1");
115+
Partition p2 = olapTable.getPartition("p2");
116+
Assertions.assertNotNull(p1);
117+
Assertions.assertNotNull(p2);
118+
119+
// Save original distribution info for p2 to restore later
120+
DistributionInfo originalDistInfo = p2.getDistributionInfo();
121+
122+
try {
123+
// Change p2's distribution columns to k2 (different from p1's k1)
124+
HashDistributionInfo differentDistInfo = new HashDistributionInfo(
125+
3, Lists.newArrayList(new Column("k2", IntegerType.INT)));
126+
p2.setDistributionInfo(differentDistInfo);
127+
128+
List<Long> partitionIds = olapTable.getPartitions().stream()
129+
.map(Partition::getId).collect(Collectors.toList());
130+
131+
StarRocksException exception = Assertions.assertThrows(StarRocksException.class, () -> {
132+
OlapTableSink.createPartition(db.getId(), olapTable, null,
133+
false, 0, partitionIds, null);
134+
});
135+
Assertions.assertTrue(exception.getMessage().contains("different distribute columns"));
136+
} finally {
137+
p2.setDistributionInfo(originalDistInfo);
138+
}
139+
}
140+
141+
@Test
142+
public void testListPartitionWithDifferentDistributionColumns() {
143+
Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb("db2");
144+
OlapTable olapTable = (OlapTable) GlobalStateMgr.getCurrentState().getLocalMetastore()
145+
.getTable(db.getFullName(), "tbl_list");
146+
147+
Partition p1 = olapTable.getPartition("p1");
148+
Partition p2 = olapTable.getPartition("p2");
149+
Assertions.assertNotNull(p1);
150+
Assertions.assertNotNull(p2);
151+
152+
DistributionInfo originalDistInfo = p2.getDistributionInfo();
153+
154+
try {
155+
HashDistributionInfo differentDistInfo = new HashDistributionInfo(
156+
3, Lists.newArrayList(new Column("k2", IntegerType.INT)));
157+
p2.setDistributionInfo(differentDistInfo);
158+
159+
List<Long> partitionIds = olapTable.getPartitions().stream()
160+
.map(Partition::getId).collect(Collectors.toList());
161+
162+
StarRocksException exception = Assertions.assertThrows(StarRocksException.class, () -> {
163+
OlapTableSink.createPartition(db.getId(), olapTable, null,
164+
false, 0, partitionIds, null);
165+
});
166+
Assertions.assertTrue(exception.getMessage().contains("different distribute columns"));
167+
} finally {
168+
p2.setDistributionInfo(originalDistInfo);
169+
}
170+
}
82171
}

0 commit comments

Comments
 (0)