From b3d4c5f9558f11bc2ce21943967a512a64d6dfbc Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Wed, 11 Nov 2026 15:13:37 +0800 Subject: [PATCH] Fix relational insert tablet redirect row count --- .../write/RelationalInsertTabletNode.java | 4 +-- .../node/write/WritePlanNodeSplitTest.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java index 50924da4447b9..28bd6eeffa4ca 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java @@ -287,8 +287,8 @@ protected Map> splitByReplicaSet( subRanges.add(splitInfo.ranges.get(2 * i + 1)); } } - final List redirectNodeList = new ArrayList<>(times.length); - for (int i = 0; i < times.length; i++) { + final List redirectNodeList = new ArrayList<>(rowCount); + for (int i = 0; i < rowCount; i++) { final IDeviceID deviceId = getDeviceID(i); redirectNodeList.add(dataNodeLocationMap.get(deviceId)); } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/node/write/WritePlanNodeSplitTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/node/write/WritePlanNodeSplitTest.java index f7da4e0614496..f4d83b19e7f58 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/node/write/WritePlanNodeSplitTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/planner/node/write/WritePlanNodeSplitTest.java @@ -411,6 +411,35 @@ public void testSplitRelationalInsertTablet() throws IllegalPathException { } } + @Test + public void testSplitRelationalInsertTabletUsesRowCountForRedirects() + throws IllegalPathException { + RelationalInsertTabletNode relationalInsertTabletNode = + new RelationalInsertTabletNode(new PlanNodeId("plan node with spare row capacity")); + relationalInsertTabletNode.setTargetPath(new PartialPath("root.sg1")); + relationalInsertTabletNode.setTimes(new long[] {1, 2, 3, 4}); + relationalInsertTabletNode.setDataTypes(new TSDataType[] {TSDataType.STRING, TSDataType.INT32}); + Binary device = new Binary("d1", StandardCharsets.UTF_8); + relationalInsertTabletNode.setColumns( + new Object[] {new Binary[] {device, device, device, device}, new int[] {10, 20, 30, 40}}); + relationalInsertTabletNode.setColumnCategories( + new TsTableColumnCategory[] {TsTableColumnCategory.TAG, TsTableColumnCategory.FIELD}); + relationalInsertTabletNode.setRowCount(2); + + DataPartitionQueryParam dataPartitionQueryParam = new DataPartitionQueryParam(); + dataPartitionQueryParam.setDeviceID(relationalInsertTabletNode.getDeviceID(0)); + dataPartitionQueryParam.setTimePartitionSlotList( + relationalInsertTabletNode.getTimePartitionSlots()); + Analysis analysis = new Analysis(); + analysis.setDataPartitionInfo( + getDataPartition(Collections.singletonList(dataPartitionQueryParam))); + + List splitNodes = relationalInsertTabletNode.splitByPartition(analysis); + + Assert.assertEquals(1, splitNodes.size()); + Assert.assertEquals(2, analysis.getRedirectNodeList().size()); + } + @Test public void testInsertMultiTablets() throws IllegalPathException { InsertMultiTabletsNode insertMultiTabletsNode =