You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/12/03 11:46:19 UTC

[iotdb] branch fix_tablet_binary_bug created (now 2742bfa)

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

qiaojialin pushed a change to branch fix_tablet_binary_bug
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 2742bfa  fix insert partial tablet with binary NullPointer bug

This branch includes the following new commits:

     new 2742bfa  fix insert partial tablet with binary NullPointer bug

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: fix insert partial tablet with binary NullPointer bug

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

qiaojialin pushed a commit to branch fix_tablet_binary_bug
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 2742bfa710ca9e7596fe7a3f255c88e994f4c731
Author: qiaojialin <64...@qq.com>
AuthorDate: Thu Dec 3 19:45:47 2020 +0800

    fix insert partial tablet with binary NullPointer bug
---
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java | 48 ++++++++++++++++++++++
 .../apache/iotdb/tsfile/write/record/Tablet.java   |  5 ++-
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
index 63ea32f..06db1ff 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 import java.util.Set;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -43,6 +44,10 @@ import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -97,6 +102,49 @@ public class IoTDBSessionSimpleIT {
   }
 
   @Test
+  public void testInsertPartialTablet()
+      throws IoTDBConnectionException, StatementExecutionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    List<MeasurementSchema> schemaList = new ArrayList<>();
+    schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
+    schemaList.add(new MeasurementSchema("s2", TSDataType.DOUBLE));
+    schemaList.add(new MeasurementSchema("s3", TSDataType.TEXT));
+
+    Tablet tablet = new Tablet("root.sg.d", schemaList, 100);
+
+    long timestamp = System.currentTimeMillis();
+
+    for (long row = 0; row < 10; row++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, timestamp);
+      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);
+        tablet.reset();
+      }
+      timestamp++;
+    }
+
+    if (tablet.rowSize != 0) {
+      session.insertTablet(tablet);
+      tablet.reset();
+    }
+
+    SessionDataSet dataSet = session.executeQueryStatement("select count(*) from root");
+    while (dataSet.hasNext()) {
+      RowRecord rowRecord = dataSet.next();
+      Assert.assertEquals(10L, rowRecord.getFields().get(0).getLongV());
+      Assert.assertEquals(10L, rowRecord.getFields().get(1).getLongV());
+      Assert.assertEquals(10L, rowRecord.getFields().get(2).getLongV());
+    }
+    session.close();
+  }
+
+  @Test
   public void testInsertByStrAndInferType()
       throws IoTDBConnectionException, StatementExecutionException {
     session = new Session("127.0.0.1", 6667, "root", "root");
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/Tablet.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/Tablet.java
index 3ccd884..a8b58a1 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/Tablet.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/Tablet.java
@@ -235,8 +235,9 @@ public class Tablet {
           break;
         case TEXT:
           valueOccupation += rowSize * 4;
-          for (Binary value : (Binary[]) values[i]) {
-            valueOccupation += value.getLength();
+          Binary[] binaries = (Binary[]) values[i];
+          for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
+            valueOccupation += binaries[rowIndex].getLength();
           }
           break;
         default: