diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index 598392d3918f797..16cec127bff2560 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -639,6 +639,10 @@ public Status resetIdsForRestore(Env env, Database db, ReplicaAllocation restore return Status.OK; } + public int getIndexNumber() { + return indexIdToMeta.size(); + } + public Map getIndexIdToMeta() { return indexIdToMeta; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapTableSink.java index 223f6b45e53c5da..bd1f6c8bff27c85 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapTableSink.java @@ -174,6 +174,16 @@ public void updateLoadId(TUniqueId newLoadId) { // must called after tupleDescriptor is computed public void complete(Analyzer analyzer) throws UserException { + for (Long partitionId : partitionIds) { + Partition partition = dstTable.getPartition(partitionId); + if (dstTable.getIndexNumber() != partition.getMaterializedIndices(IndexExtState.ALL).size()) { + throw new UserException( + "table's index number not equal with partition's index number. table's index number=" + + dstTable.getIndexIdToMeta().size() + ", partition's index number=" + + partition.getMaterializedIndices(IndexExtState.ALL).size()); + } + } + TOlapTableSink tSink = tDataSink.getOlapTableSink(); tSink.setTableId(dstTable.getId()); diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/OlapTableSinkTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/OlapTableSinkTest.java index dc98026a00eb2c1..0ebea0e3b35c68b 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/OlapTableSinkTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/OlapTableSinkTest.java @@ -92,6 +92,8 @@ public void testSinglePartition() throws UserException { new Expectations() { { + dstTable.getIndexNumber(); + result = 1; dstTable.getId(); result = 1; dstTable.getPartitionInfo(); @@ -128,6 +130,8 @@ public void testRangePartition( new Expectations() { { + dstTable.getIndexNumber(); + result = 1; dstTable.getId(); result = 1; dstTable.getPartitionInfo(); @@ -190,6 +194,8 @@ public void testListPartition( new Expectations() { { + dstTable.getIndexNumber(); + result = 1; dstTable.getId(); result = 1; dstTable.getPartitionInfo();