You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/09/16 04:28:19 UTC

[iotdb] branch iotdb-4428 created (now e41fa63e19)

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a change to branch iotdb-4428
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at e41fa63e19 [IOTDB-4428] Fix partital insert by session NPE

This branch includes the following new commits:

     new e41fa63e19 [IOTDB-4428] Fix partital insert by session NPE

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: [IOTDB-4428] Fix partital insert by session NPE

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch iotdb-4428
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit e41fa63e198eb0676d05773f403d8a94dce0f905
Author: HTHou <hh...@outlook.com>
AuthorDate: Fri Sep 16 12:27:58 2022 +0800

    [IOTDB-4428] Fix partital insert by session NPE
---
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java | 28 +++++++++++++++-------
 .../db/engine/memtable/WritableMemChunkGroup.java  | 12 +++-------
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java b/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
index 486678d6e5..7e135e56ae 100644
--- a/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
+++ b/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
@@ -98,6 +98,12 @@ public class IoTDBSessionSimpleIT {
     session = new Session("127.0.0.1", 6667, "root", "root");
     session.open();
 
+    session.createTimeseries(
+        "root.sg.d.s1", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.LZ4);
+    session.createTimeseries(
+        "root.sg.d.s2", TSDataType.FLOAT, TSEncoding.PLAIN, CompressionType.LZ4);
+    session.createTimeseries(
+        "root.sg.d.s3", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.LZ4);
     List<MeasurementSchema> schemaList = new ArrayList<>();
     schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
     schemaList.add(new MeasurementSchema("s2", TSDataType.DOUBLE));
@@ -105,33 +111,39 @@ public class IoTDBSessionSimpleIT {
 
     Tablet tablet = new Tablet("root.sg.d", schemaList, 10);
 
-    long timestamp = System.currentTimeMillis();
-
     for (long row = 0; row < 15; row++) {
       int rowIndex = tablet.rowSize++;
-      tablet.addTimestamp(rowIndex, timestamp);
+      tablet.addTimestamp(rowIndex, row);
       tablet.addValue("s1", rowIndex, 1L);
       tablet.addValue("s2", rowIndex, 1D);
       tablet.addValue("s3", rowIndex, new Binary("1"));
       if (tablet.rowSize == tablet.getMaxRowNumber()) {
-        session.insertTablet(tablet, true);
+        try {
+          session.insertTablet(tablet, true);
+        } catch (StatementExecutionException e) {
+          Assert.assertTrue(e.getMessage().contains("is not consistent"));
+        }
         tablet.reset();
       }
-      timestamp++;
     }
 
     if (tablet.rowSize != 0) {
-      session.insertTablet(tablet);
+      try {
+        session.insertTablet(tablet);
+      } catch (StatementExecutionException e) {
+        Assert.assertTrue(e.getMessage().contains("is not consistent"));
+      }
       tablet.reset();
     }
 
-    SessionDataSet dataSet = session.executeQueryStatement("select count(*) from root");
+    SessionDataSet dataSet = session.executeQueryStatement("select count(*) from root.**");
     while (dataSet.hasNext()) {
       RowRecord rowRecord = dataSet.next();
       Assert.assertEquals(15L, rowRecord.getFields().get(0).getLongV());
       Assert.assertEquals(15L, rowRecord.getFields().get(1).getLongV());
-      Assert.assertEquals(15L, rowRecord.getFields().get(2).getLongV());
+      Assert.assertEquals(0, rowRecord.getFields().get(2).getLongV());
     }
+    dataSet.close();
     session.close();
   }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkGroup.java b/server/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkGroup.java
index 4dc8e082a0..703ac67fad 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkGroup.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkGroup.java
@@ -50,19 +50,16 @@ public class WritableMemChunkGroup implements IWritableMemChunkGroup {
       List<IMeasurementSchema> schemaList,
       int start,
       int end) {
-    int emptyColumnCount = 0;
     for (int i = 0; i < columns.length; i++) {
       if (columns[i] == null) {
-        emptyColumnCount++;
         continue;
       }
-      IWritableMemChunk memChunk =
-          createMemChunkIfNotExistAndGet(schemaList.get(i - emptyColumnCount));
+      IWritableMemChunk memChunk = createMemChunkIfNotExistAndGet(schemaList.get(i));
       memChunk.write(
           times,
           columns[i],
           bitMaps == null ? null : bitMaps[i],
-          schemaList.get(i - emptyColumnCount).getType(),
+          schemaList.get(i).getType(),
           start,
           end);
     }
@@ -96,14 +93,11 @@ public class WritableMemChunkGroup implements IWritableMemChunkGroup {
 
   @Override
   public void write(long insertTime, Object[] objectValue, List<IMeasurementSchema> schemaList) {
-    int emptyColumnCount = 0;
     for (int i = 0; i < objectValue.length; i++) {
       if (objectValue[i] == null) {
-        emptyColumnCount++;
         continue;
       }
-      IWritableMemChunk memChunk =
-          createMemChunkIfNotExistAndGet(schemaList.get(i - emptyColumnCount));
+      IWritableMemChunk memChunk = createMemChunkIfNotExistAndGet(schemaList.get(i));
       memChunk.write(insertTime, objectValue[i]);
     }
   }