This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 207bbe8950b Keep the order of times after spliting
RelationalInsertTabletNode (#13886)
207bbe8950b is described below
commit 207bbe8950b257295f80451ba9cfe6b4ee23cf96
Author: Haonan <[email protected]>
AuthorDate: Wed Oct 23 22:21:35 2024 +0800
Keep the order of times after spliting RelationalInsertTabletNode (#13886)
---
.../relational/it/db/it/IoTDBInsertTableIT.java | 2 +-
.../planner/plan/node/write/InsertTabletNode.java | 3 +-
.../db/storageengine/dataregion/DataRegion.java | 2 +-
.../planner/node/write/WritePlanNodeSplitTest.java | 57 ++++++++++++++++++++++
4 files changed, 61 insertions(+), 3 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
index e1f084d5fa9..49e870e7abf 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
@@ -955,7 +955,7 @@ public class IoTDBInsertTableIT {
Assert.assertTrue(record.getFields().get(0).getLongV() >
timeLowerBound);
count++;
}
- Assert.assertTrue(count > 0 && count < 4);
+ Assert.assertEquals(2, count);
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
index 2c0ac5a96dc..98a072fcee0 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
@@ -65,6 +65,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -219,7 +220,7 @@ public class InsertTabletNode extends InsertNode implements
WALEntryValue {
int startLoc = 0; // included
IDeviceID currDeviceId = getDeviceID(0);
- Map<IDeviceID, PartitionSplitInfo> deviceIDSplitInfoMap = new HashMap<>();
+ Map<IDeviceID, PartitionSplitInfo> deviceIDSplitInfoMap = new
LinkedHashMap<>();
for (int i = 1; i < times.length; i++) { // times are sorted in session
API.
IDeviceID nextDeviceId = getDeviceID(i);
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
index 1772521a498..16654ea8b16 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
@@ -1232,7 +1232,7 @@ public class DataRegion implements IDataRegionForQuery {
split(insertTabletNode, start, end, splitInfo);
start = end;
}
- noFailure = noFailure && doInsert(insertTabletNode, splitInfo, results,
costsForMetrics);
+ noFailure = doInsert(insertTabletNode, splitInfo, results,
costsForMetrics) && noFailure;
if (CommonDescriptor.getInstance().getConfig().isLastCacheEnable()
&& !insertTabletNode.isGeneratedByRemoteConsensusLeader()) {
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 c3ca365befb..e0d3354d2b1 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
@@ -32,6 +32,7 @@ import org.apache.iotdb.commons.partition.DataPartition;
import org.apache.iotdb.commons.partition.DataPartitionQueryParam;
import org.apache.iotdb.commons.partition.executor.SeriesPartitionExecutor;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
import org.apache.iotdb.commons.utils.TimePartitionUtils;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.queryengine.plan.analyze.Analysis;
@@ -42,13 +43,16 @@ import
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNod
import
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowsNode;
import
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowsOfOneDeviceNode;
import
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertTabletNode;
+import
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.RelationalInsertTabletNode;
import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -245,6 +249,59 @@ public class WritePlanNodeSplitTest {
}
}
+ @Test
+ public void testSplitRelationalInsertTablet() throws IllegalPathException {
+ RelationalInsertTabletNode relationalInsertTabletNode =
+ new RelationalInsertTabletNode(new PlanNodeId("plan node 1"));
+
+ relationalInsertTabletNode.setTargetPath(new PartialPath("root.sg1"));
+ relationalInsertTabletNode.setTimes(
+ new long[] {-200, -101, 1, 60, 120, 180, 270, 290, 360, 375, 440,
470});
+ relationalInsertTabletNode.setDataTypes(new TSDataType[]
{TSDataType.STRING, TSDataType.INT32});
+ Binary d1 = new Binary("d1", StandardCharsets.UTF_8);
+ Binary d2 = new Binary("d2", StandardCharsets.UTF_8);
+ relationalInsertTabletNode.setColumns(
+ new Object[] {
+ new Binary[] {
+ d1, d2, d1, d2, d1, d2, d1, d2, d1, d2, d1, d2,
+ },
+ new int[] {-20, -10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
+ });
+ relationalInsertTabletNode.setColumnCategories(
+ new TsTableColumnCategory[] {TsTableColumnCategory.ID,
TsTableColumnCategory.MEASUREMENT});
+ relationalInsertTabletNode.setRowCount(12);
+
+ List<DataPartitionQueryParam> dataPartitionQueryParamList = new
ArrayList<>();
+ DataPartitionQueryParam dataPartitionQueryParam = new
DataPartitionQueryParam();
+
dataPartitionQueryParam.setDeviceID(relationalInsertTabletNode.getDeviceID(0));
+ dataPartitionQueryParam.setTimePartitionSlotList(
+ relationalInsertTabletNode.getTimePartitionSlots());
+
+ dataPartitionQueryParamList.add(dataPartitionQueryParam);
+ dataPartitionQueryParam = new DataPartitionQueryParam();
+
dataPartitionQueryParam.setDeviceID(relationalInsertTabletNode.getDeviceID(1));
+ dataPartitionQueryParam.setTimePartitionSlotList(
+ relationalInsertTabletNode.getTimePartitionSlots());
+ dataPartitionQueryParamList.add(dataPartitionQueryParam);
+
+ DataPartition dataPartition =
getDataPartition(dataPartitionQueryParamList);
+ Analysis analysis = new Analysis();
+ analysis.setDataPartitionInfo(dataPartition);
+
+ List<WritePlanNode> insertTabletNodeList =
+ relationalInsertTabletNode.splitByPartition(analysis);
+
+ Assert.assertEquals(6, insertTabletNodeList.size());
+ for (WritePlanNode insertNode : insertTabletNodeList) {
+ InsertTabletNode tabletNode = (InsertTabletNode) insertNode;
+ Assert.assertEquals(2, tabletNode.getTimes().length);
+ // keep the time order after split
+ Assert.assertTrue(tabletNode.getTimes()[0] < tabletNode.getTimes()[1]);
+ TConsensusGroupId regionId =
tabletNode.getDataRegionReplicaSet().getRegionId();
+ Assert.assertEquals(getRegionIdByTime(tabletNode.getMinTime()),
regionId.getId());
+ }
+ }
+
@Test
public void testInsertMultiTablets() throws IllegalPathException {
InsertMultiTabletsNode insertMultiTabletsNode =