This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch iotdb
in repository https://gitbox.apache.org/repos/asf/tsfile.git
The following commit(s) were added to refs/heads/iotdb by this push:
new 0d6ab095 Fix tablet isNull method not correct (#255)
0d6ab095 is described below
commit 0d6ab095b77f70b26447c7c704dbc4bd184a5a68
Author: Haonan <[email protected]>
AuthorDate: Wed Oct 9 10:47:34 2024 +0800
Fix tablet isNull method not correct (#255)
* Fix tablet isNull method not correct
* remove useless method
(cherry picked from commit 3eea99ddec8c4ccda12f03b09149c0beae1f64da)
---
.../org/apache/tsfile/write/record/Tablet.java | 60 +---------------------
.../org/apache/tsfile/write/record/TabletTest.java | 50 ++++++++++++++++++
2 files changed, 51 insertions(+), 59 deletions(-)
diff --git
a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
index c826499d..8c042250 100644
--- a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
+++ b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
@@ -373,64 +373,6 @@ public class Tablet {
return valueColumn;
}
- public int getTimeBytesSize() {
- return rowSize * 8;
- }
-
- /**
- * @return Total bytes of values
- */
- public int getTotalValueOccupation() {
- int valueOccupation = 0;
- int columnIndex = 0;
- for (IMeasurementSchema schema : schemas) {
- valueOccupation += calOccupationOfOneColumn(schema.getType(),
columnIndex);
- columnIndex++;
- }
- // Add bitmap size if the tablet has bitMaps
- if (bitMaps != null) {
- for (BitMap bitMap : bitMaps) {
- // Marker byte
- valueOccupation++;
- if (bitMap != null && !bitMap.isAllUnmarked()) {
- valueOccupation += rowSize / Byte.SIZE + 1;
- }
- }
- }
- return valueOccupation;
- }
-
- private int calOccupationOfOneColumn(TSDataType dataType, int columnIndex) {
- int valueOccupation = 0;
- switch (dataType) {
- case BOOLEAN:
- valueOccupation += rowSize;
- break;
- case INT32:
- case FLOAT:
- case DATE:
- valueOccupation += rowSize * 4;
- break;
- case INT64:
- case DOUBLE:
- case TIMESTAMP:
- valueOccupation += rowSize * 8;
- break;
- case TEXT:
- case BLOB:
- case STRING:
- valueOccupation += rowSize * 4;
- Binary[] binaries = (Binary[]) values[columnIndex];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- valueOccupation += binaries[rowIndex].getLength();
- }
- break;
- default:
- throw new
UnSupportedDataTypeException(String.format(NOT_SUPPORT_DATATYPE, dataType));
- }
- return valueOccupation;
- }
-
/** Serialize {@link Tablet} */
public ByteBuffer serialize() throws IOException {
try (PublicBAOS byteArrayOutputStream = new PublicBAOS();
@@ -920,7 +862,7 @@ public class Tablet {
}
public boolean isNull(int i, int j) {
- return bitMaps != null && bitMaps[j] != null && !bitMaps[j].isMarked(i);
+ return bitMaps != null && bitMaps[j] != null && bitMaps[j].isMarked(i);
}
/**
diff --git
a/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
b/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
index 325fb301..5d57498e 100644
--- a/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
+++ b/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
public class TabletTest {
@@ -148,4 +149,53 @@ public class TabletTest {
fail();
}
}
+
+ @Test
+ public void testSerializationAndDeSerializationNull() {
+ final String deviceId = "root.sg";
+ final List<IMeasurementSchema> measurementSchemas = new ArrayList<>();
+ measurementSchemas.add(new MeasurementSchema("s0", TSDataType.INT32,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s1", TSDataType.INT64,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s2", TSDataType.FLOAT,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s3", TSDataType.DOUBLE,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s4", TSDataType.BOOLEAN,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s5", TSDataType.TEXT,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s6", TSDataType.STRING,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s7", TSDataType.BLOB,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s8", TSDataType.TIMESTAMP,
TSEncoding.PLAIN));
+ measurementSchemas.add(new MeasurementSchema("s9", TSDataType.DATE,
TSEncoding.PLAIN));
+
+ final int rowSize = 1000;
+ final Tablet tablet = new Tablet(deviceId, measurementSchemas);
+ tablet.rowSize = rowSize;
+ tablet.initBitMaps();
+ for (int i = 0; i < rowSize; i++) {
+ tablet.addTimestamp(i, i);
+ tablet.addValue(measurementSchemas.get(0).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(1).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(2).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(3).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(4).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(5).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(6).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(7).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(8).getMeasurementId(), i, null);
+ tablet.addValue(measurementSchemas.get(9).getMeasurementId(), i, null);
+ }
+
+ try {
+ final ByteBuffer byteBuffer = tablet.serialize();
+ final Tablet newTablet = Tablet.deserialize(byteBuffer);
+ assertEquals(tablet, newTablet);
+ for (int i = 0; i < rowSize; i++) {
+ for (int j = 0; j < tablet.getSchemas().size(); j++) {
+ assertNull(tablet.getValue(i, j));
+ assertNull(newTablet.getValue(i, j));
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
}