From d30d283a63745ab637ac0f1cc87b28fa6e90721b Mon Sep 17 00:00:00 2001 From: shuwenwei <55970239+shuwenwei@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:52:15 +0800 Subject: [PATCH] Add IMeasurementSchema list conversion methods (#303) * add IMeasurementSchema list conversion methods * modify usage * modify TsFileWriter * modify exception * copy schema in Tablet constructor * make Tablet.rowSize access to private --- .../org/apache/tsfile/tools/TsFileTool.java | 11 ++----- .../tsfile/utils/TsFileGeneratorUtils.java | 8 ++--- .../org/apache/tsfile/utils/WriteUtils.java | 4 +-- .../org/apache/tsfile/write/TsFileWriter.java | 20 +++++++----- .../chunk/AlignedChunkGroupWriterImpl.java | 2 +- .../chunk/NonAlignedChunkGroupWriterImpl.java | 2 +- .../apache/tsfile/write/record/Tablet.java | 16 +++++++--- .../write/schema/IMeasurementSchema.java | 11 +++++++ .../apache/tsfile/read/TsFileReaderTest.java | 11 ++----- .../tsfile/tableview/PerformanceTest.java | 12 +++---- .../tsfile/tableview/TableViewTest.java | 22 +++++-------- .../write/DefaultSchemaTemplateTest.java | 9 +++--- .../write/MetadataIndexConstructorTest.java | 8 ++--- .../tsfile/write/TsFileWriteApiTest.java | 31 ++++++++++--------- .../apache/tsfile/write/TsFileWriterTest.java | 4 +-- .../tsfile/write/record/TabletTest.java | 10 +++--- 16 files changed, 94 insertions(+), 87 deletions(-) diff --git a/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java b/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java index c9116eaea..4366cee95 100644 --- a/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java +++ b/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java @@ -58,7 +58,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; public class TsFileTool { private static int THREAD_COUNT = 8; @@ -194,12 +193,8 @@ private static Tablet genTablet( Tablet tablet = new Tablet( tableSchema.getTableName(), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getMeasurementName) - .collect(Collectors.toList()), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getType) - .collect(Collectors.toList()), + IMeasurementSchema.getMeasurementNameList(tableSchema.getColumnSchemas()), + IMeasurementSchema.getDataTypeList(tableSchema.getColumnSchemas()), tableSchema.getColumnTypes(), num); @@ -237,7 +232,7 @@ private static Tablet genTablet( } } } - tablet.rowSize = num; + tablet.setRowSize(num); return tablet; } catch (Exception e) { LOGGER.error("Failed to parse csv file", e); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileGeneratorUtils.java b/java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileGeneratorUtils.java index f669bfecc..6db55669d 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileGeneratorUtils.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileGeneratorUtils.java @@ -122,14 +122,14 @@ public static void writeWithTablet( long sensorNum = schemas.size(); for (long r = 0; r < rowNum; r++, startValue++) { - int row = tablet.rowSize++; - timestamps[row] = startTime++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, startTime++); for (int i = 0; i < sensorNum; i++) { long[] sensor = (long[]) values[i]; sensor[row] = startValue; } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { if (isAligned) { tsFileWriter.writeAligned(tablet); } else { @@ -139,7 +139,7 @@ public static void writeWithTablet( } } // write - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { if (isAligned) { tsFileWriter.writeAligned(tablet); } else { diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/WriteUtils.java b/java/tsfile/src/main/java/org/apache/tsfile/utils/WriteUtils.java index 542d252fd..cbd9e7014 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/utils/WriteUtils.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/WriteUtils.java @@ -36,7 +36,7 @@ public class WriteUtils { public static List> splitTabletByDevice(Tablet tablet) { List> result = new ArrayList<>(); IDeviceID lastDeviceID = null; - for (int i = 0; i < tablet.rowSize; i++) { + for (int i = 0; i < tablet.getRowSize(); i++) { final IDeviceID currDeviceID = tablet.getDeviceID(i); if (!currDeviceID.equals(lastDeviceID)) { if (lastDeviceID != null) { @@ -45,7 +45,7 @@ public static List> splitTabletByDevice(Tablet tablet) lastDeviceID = currDeviceID; } } - result.add(new Pair<>(lastDeviceID, tablet.rowSize)); + result.add(new Pair<>(lastDeviceID, tablet.getRowSize())); return result; } diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java b/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java index 28003c594..01116b1e9 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java @@ -522,8 +522,11 @@ private IChunkGroupWriter tryToInitialGroupWriter(IDeviceID deviceId, boolean is */ @TsFileApi public boolean writeRecord(TSRecord record) throws IOException, WriteProcessException { - boolean isAligned = getSchema().getSeriesSchema(record.deviceId).isAligned(); - checkIsTimeseriesExist(record, isAligned); + MeasurementGroup measurementGroup = getSchema().getSeriesSchema(record.deviceId); + if (measurementGroup == null) { + throw new NoDeviceException(record.deviceId.toString()); + } + checkIsTimeseriesExist(record, measurementGroup.isAligned()); recordCount += groupWriters.get(record.deviceId).write(record.time, record.dataPointList); return checkMemorySizeAndMayFlushChunks(); } @@ -537,16 +540,19 @@ public boolean writeRecord(TSRecord record) throws IOException, WriteProcessExce */ @TsFileApi public boolean write(Tablet tablet) throws IOException, WriteProcessException { + IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(tablet.getDeviceId()); + MeasurementGroup measurementGroup = getSchema().getSeriesSchema(deviceID); + if (measurementGroup == null) { + throw new NoDeviceException(deviceID.toString()); + } // make sure the ChunkGroupWriter for this Tablet exist - checkIsTimeseriesExist(tablet, false); + checkIsTimeseriesExist(tablet, measurementGroup.isAligned()); // get corresponding ChunkGroupWriter and write this Tablet - recordCount += - groupWriters - .get(IDeviceID.Factory.DEFAULT_FACTORY.create(tablet.getDeviceId())) - .write(tablet); + recordCount += groupWriters.get(deviceID).write(tablet); return checkMemorySizeAndMayFlushChunks(); } + @Deprecated public boolean writeAligned(Tablet tablet) throws IOException, WriteProcessException { // make sure the ChunkGroupWriter for this Tablet exist checkIsTimeseriesExist(tablet, true); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java b/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java index add8018b0..e50d8a5cb 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java @@ -189,7 +189,7 @@ public int write(long time, List data) throws WriteProcessException, @Override public int write(Tablet tablet) throws IOException, WriteProcessException { - return write(tablet, 0, tablet.rowSize); + return write(tablet, 0, tablet.getRowSize()); } @Override diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/NonAlignedChunkGroupWriterImpl.java b/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/NonAlignedChunkGroupWriterImpl.java index 45e3bdbfe..75e5a9bc8 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/NonAlignedChunkGroupWriterImpl.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/chunk/NonAlignedChunkGroupWriterImpl.java @@ -103,7 +103,7 @@ public int write(long time, List data) throws IOException, WriteProce @Override public int write(Tablet tablet) throws IOException, WriteProcessException { - return write(tablet, 0, tablet.rowSize); + return write(tablet, 0, tablet.getRowSize()); } @Override 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 e1da3c05c..7185fffba 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 @@ -92,8 +92,7 @@ public class Tablet { */ private boolean autoUpdateBitMaps = false; - /** The number of rows to include in this {@link Tablet} */ - public int rowSize; + private int rowSize; /** The maximum number of rows for this {@link Tablet} */ private final int maxRowNumber; @@ -112,7 +111,7 @@ public Tablet(String deviceId, List schemas) { public Tablet(String deviceId, List schemas, int maxRowNumber) { this.insertTargetName = deviceId; - this.schemas = schemas; + this.schemas = new ArrayList<>(schemas); setColumnCategories(ColumnCategory.nCopy(ColumnCategory.MEASUREMENT, schemas.size())); this.maxRowNumber = maxRowNumber; measurementIndex = new HashMap<>(); @@ -458,7 +457,7 @@ public int getMaxRowNumber() { /** Reset Tablet to the default state - set the rowSize to 0 and reset bitMaps */ public void reset() { - rowSize = 0; + this.rowSize = 0; if (bitMaps != null) { for (BitMap bitMap : bitMaps) { if (bitMap == null) { @@ -1079,6 +1078,15 @@ public void setColumnCategories(List columnCategories) { } } + /** The number of rows to include in this {@link Tablet} */ + public int getRowSize() { + return rowSize; + } + + public void setRowSize(int rowSize) { + this.rowSize = rowSize; + } + public enum ColumnCategory { ID, MEASUREMENT, diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/schema/IMeasurementSchema.java b/java/tsfile/src/main/java/org/apache/tsfile/write/schema/IMeasurementSchema.java index be3256534..740e76a55 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/schema/IMeasurementSchema.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/schema/IMeasurementSchema.java @@ -29,6 +29,7 @@ import java.nio.ByteBuffer; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public interface IMeasurementSchema { @@ -88,4 +89,14 @@ public interface IMeasurementSchema { int partialSerializeTo(OutputStream outputStream) throws IOException; boolean isLogicalView(); + + static List getMeasurementNameList(List schemaList) { + return schemaList.stream() + .map(IMeasurementSchema::getMeasurementName) + .collect(Collectors.toList()); + } + + static List getDataTypeList(List schemaList) { + return schemaList.stream().map(IMeasurementSchema::getType).collect(Collectors.toList()); + } } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/read/TsFileReaderTest.java b/java/tsfile/src/test/java/org/apache/tsfile/read/TsFileReaderTest.java index 01f8de570..9445c559d 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/read/TsFileReaderTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/read/TsFileReaderTest.java @@ -65,7 +65,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.stream.Collectors; import static org.apache.tsfile.read.filter.factory.ValueFilterApi.DEFAULT_MEASUREMENT_INDEX; @@ -613,12 +612,8 @@ public void testGetTableDeviceMethods() throws IOException, WriteProcessExceptio Tablet tablet = new Tablet( tableSchema.getTableName(), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getMeasurementName) - .collect(Collectors.toList()), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getType) - .collect(Collectors.toList()), + IMeasurementSchema.getMeasurementNameList(tableSchema.getColumnSchemas()), + IMeasurementSchema.getDataTypeList(tableSchema.getColumnSchemas()), tableSchema.getColumnTypes()); String[][] ids = @@ -640,7 +635,7 @@ public void testGetTableDeviceMethods() throws IOException, WriteProcessExceptio new StringArrayDeviceID(tableSchema.getTableName(), ids[i][0], ids[i][1], ids[i][2])); tablet.addValue("s1", i, i); } - tablet.rowSize = ids.length; + tablet.setRowSize(ids.length); writer.writeTable(tablet); } try (TsFileReader tsFileReader = new TsFileReader(file)) { diff --git a/java/tsfile/src/test/java/org/apache/tsfile/tableview/PerformanceTest.java b/java/tsfile/src/test/java/org/apache/tsfile/tableview/PerformanceTest.java index 11eea0b84..6547172b6 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/tableview/PerformanceTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/tableview/PerformanceTest.java @@ -215,7 +215,7 @@ private void testTable() throws IOException, WriteProcessException, ReadProcessE startTime = System.nanoTime(); tsFileWriter.writeTable( tablet, - Collections.singletonList(new Pair<>(tablet.getDeviceID(0), tablet.rowSize))); + Collections.singletonList(new Pair<>(tablet.getDeviceID(0), tablet.getRowSize()))); writeTimeSum += System.nanoTime() - startTime; } } @@ -282,7 +282,7 @@ private void fillTreeTablet(Tablet tablet, int tableNum, int deviceNum, int tabl for (int valNum = 0; valNum < pointPerSeries; valNum++) { tablet.timestamps[valNum] = (long) tabletNum * pointPerSeries + valNum; } - tablet.rowSize = pointPerSeries; + tablet.setRowSize(pointPerSeries); } private Tablet initTableTablet() { @@ -293,10 +293,8 @@ private Tablet initTableTablet() { columnCategories.addAll(ColumnCategory.nCopy(ColumnCategory.MEASUREMENT, measurementSchemaCnt)); return new Tablet( null, - measurementSchemas.stream() - .map(IMeasurementSchema::getMeasurementName) - .collect(Collectors.toList()), - measurementSchemas.stream().map(IMeasurementSchema::getType).collect(Collectors.toList()), + IMeasurementSchema.getMeasurementNameList(measurementSchemas), + IMeasurementSchema.getDataTypeList(measurementSchemas), columnCategories, pointPerSeries); } @@ -319,7 +317,7 @@ private void fillTableTablet(Tablet tablet, int tableNum, int deviceNum, int tab for (int valNum = 0; valNum < pointPerSeries; valNum++) { tablet.timestamps[valNum] = (long) tabletNum * pointPerSeries + valNum; } - tablet.rowSize = pointPerSeries; + tablet.setRowSize(pointPerSeries); } private void registerTree(TsFileWriter writer) throws WriteProcessException { diff --git a/java/tsfile/src/test/java/org/apache/tsfile/tableview/TableViewTest.java b/java/tsfile/src/test/java/org/apache/tsfile/tableview/TableViewTest.java index 948456945..c525e3102 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/tableview/TableViewTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/tableview/TableViewTest.java @@ -210,12 +210,8 @@ public void testDeviceIdWithNull() throws Exception { Tablet tablet = new Tablet( tableSchema.getTableName(), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getMeasurementName) - .collect(Collectors.toList()), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getType) - .collect(Collectors.toList()), + IMeasurementSchema.getMeasurementNameList(tableSchema.getColumnSchemas()), + IMeasurementSchema.getDataTypeList(tableSchema.getColumnSchemas()), tableSchema.getColumnTypes()); ids = @@ -235,7 +231,7 @@ public void testDeviceIdWithNull() throws Exception { tablet.addValue("id3", i, ids[i][2]); tablet.addValue("s1", i, i); } - tablet.rowSize = ids.length; + tablet.setRowSize(ids.length); writer.writeTable(tablet); } @@ -469,7 +465,7 @@ public void testHybridWrite() throws Exception { List selectedSeries = new ArrayList<>(); Set deviceIDS = new HashSet<>(); - for (int i = 0; i < tablet.rowSize; i++) { + for (int i = 0; i < tablet.getRowSize(); i++) { final IDeviceID tabletDeviceID = tablet.getDeviceID(i); if (!deviceIDS.contains(tabletDeviceID)) { deviceIDS.add(tabletDeviceID); @@ -495,12 +491,8 @@ public static Tablet genTablet(TableSchema tableSchema, int offset, int deviceNu Tablet tablet = new Tablet( tableSchema.getTableName(), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getMeasurementName) - .collect(Collectors.toList()), - tableSchema.getColumnSchemas().stream() - .map(IMeasurementSchema::getType) - .collect(Collectors.toList()), + IMeasurementSchema.getMeasurementNameList(tableSchema.getColumnSchemas()), + IMeasurementSchema.getDataTypeList(tableSchema.getColumnSchemas()), tableSchema.getColumnTypes()); for (int i = 0; i < deviceNum; i++) { @@ -515,7 +507,7 @@ public static Tablet genTablet(TableSchema tableSchema, int offset, int deviceNu } } } - tablet.rowSize = deviceNum * numTimestampPerDevice; + tablet.setRowSize(deviceNum * numTimestampPerDevice); return tablet; } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/write/DefaultSchemaTemplateTest.java b/java/tsfile/src/test/java/org/apache/tsfile/write/DefaultSchemaTemplateTest.java index d57cf30a9..5e7564b96 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/write/DefaultSchemaTemplateTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/write/DefaultSchemaTemplateTest.java @@ -63,6 +63,7 @@ public void testUsingDefaultSchemaTemplate() throws IOException, WriteProcessExc schema.put("s2", s2); writer.registerSchemaTemplate("defaultTemplate", schema, false); + writer.registerDevice("d1", "defaultTemplate"); Tablet tablet = new Tablet("d1", schemaList); long[] timestamps = tablet.timestamps; @@ -72,20 +73,20 @@ public void testUsingDefaultSchemaTemplate() throws IOException, WriteProcessExc long value = 1L; for (int r = 0; r < 10; r++, value++) { - int row = tablet.rowSize++; - timestamps[row] = timestamp++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, timestamp++); for (int i = 0; i < 2; i++) { long[] sensor = (long[]) values[i]; sensor[row] = value; } // write Tablet to TsFile - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { writer.write(tablet); tablet.reset(); } } // write Tablet to TsFile - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { writer.write(tablet); tablet.reset(); } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/write/MetadataIndexConstructorTest.java b/java/tsfile/src/test/java/org/apache/tsfile/write/MetadataIndexConstructorTest.java index eed8c1c98..32cbb6e3e 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/write/MetadataIndexConstructorTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/write/MetadataIndexConstructorTest.java @@ -482,20 +482,20 @@ private void generateFile( long timestamp = 1; long value = 1000000L; for (int r = 0; r < rowNum; r++, value++) { - int row = tablet.rowSize++; - timestamps[row] = timestamp++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, timestamp++); for (int j = 0; j < measurementNum; j++) { long[] sensor = (long[]) values[j]; sensor[row] = value; } // write Tablet to TsFile - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { tsFileWriter.writeAligned(tablet); tablet.reset(); } } // write Tablet to TsFile - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { tsFileWriter.writeAligned(tablet); tablet.reset(); } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriteApiTest.java b/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriteApiTest.java index 4a9f9f603..edade15f4 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriteApiTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriteApiTest.java @@ -369,8 +369,8 @@ public void writeNonAlignedWithTabletWithNullValue() { int sensorNum = measurementSchemas.size(); long startTime = 0; for (long r = 0; r < 10000; r++) { - int row = tablet.rowSize++; - timestamps[row] = startTime++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, startTime++); for (int i = 0; i < sensorNum - 1; i++) { if (i == 1 && r > 1000) { tablet.bitMaps[i].mark((int) r % tablet.getMaxRowNumber()); @@ -386,13 +386,13 @@ public void writeNonAlignedWithTabletWithNullValue() { dateSensor[row] = LocalDate.of(2024, 4, 1); } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { tsFileWriter.write(tablet); tablet.reset(); } } // write - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { tsFileWriter.write(tablet); tablet.reset(); } @@ -422,8 +422,8 @@ public void writeNonAlignedWithTabletWithNegativeTimestamps() { int sensorNum = measurementSchemas.size(); long startTime = -100; for (long r = 0; r < 10000; r++) { - int row = tablet.rowSize++; - timestamps[row] = startTime++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, startTime++); for (int i = 0; i < sensorNum - 1; i++) { if (i == 1 && r > 1000) { tablet.bitMaps[i].mark((int) r % tablet.getMaxRowNumber()); @@ -439,13 +439,13 @@ public void writeNonAlignedWithTabletWithNegativeTimestamps() { dateSensor[row] = LocalDate.of(2024, 4, 1); } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { tsFileWriter.write(tablet); tablet.reset(); } } // write - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { tsFileWriter.write(tablet); tablet.reset(); } @@ -475,7 +475,8 @@ public void writeAlignedWithTabletWithNullValue() { int sensorNum = measurementSchemas.size(); long startTime = 0; for (long r = 0; r < 10000; r++) { - int row = tablet.rowSize++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, startTime++); timestamps[row] = startTime++; for (int i = 0; i < sensorNum - 1; i++) { if (i == 1 && r > 1000) { @@ -492,13 +493,13 @@ public void writeAlignedWithTabletWithNullValue() { dateSensor[row] = LocalDate.of(2024, 4, 1); } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { tsFileWriter.writeAligned(tablet); tablet.reset(); } } // write - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { tsFileWriter.writeAligned(tablet); tablet.reset(); } @@ -528,8 +529,8 @@ public void writeDataToTabletsWithNegativeTimestamps() { int sensorNum = measurementSchemas.size(); long startTime = -1000; for (long r = 0; r < 10000; r++) { - int row = tablet.rowSize++; - timestamps[row] = startTime++; + int row = tablet.getRowSize(); + tablet.addTimestamp(row, startTime++); for (int i = 0; i < sensorNum - 1; i++) { if (i == 1 && r > 1000) { tablet.bitMaps[i].mark((int) r % tablet.getMaxRowNumber()); @@ -545,13 +546,13 @@ public void writeDataToTabletsWithNegativeTimestamps() { dateSensor[row] = LocalDate.of(2024, 4, 1); } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { tsFileWriter.writeAligned(tablet); tablet.reset(); } } // write - if (tablet.rowSize != 0) { + if (tablet.getRowSize() != 0) { tsFileWriter.writeAligned(tablet); tablet.reset(); } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriterTest.java b/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriterTest.java index 5e4994a86..5a925c664 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriterTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriterTest.java @@ -247,7 +247,7 @@ public void writeTablet() throws IOException, WriteProcessException { tablet.timestamps[0] = 10000; ((float[]) tablet.values[0])[0] = 5.0f; ((int[]) tablet.values[1])[0] = 5; - tablet.rowSize = 1; + tablet.setRowSize(1); writer.write(tablet); closeFile(); readOneRow(); @@ -265,7 +265,7 @@ public void writeTablet2() throws IOException, WriteProcessException { "s2", TSDataType.INT32, TSEncoding.RLE, CompressionType.SNAPPY))); tablet.timestamps[0] = 10000; ((float[]) tablet.values[0])[0] = 5.0f; - tablet.rowSize = 1; + tablet.setRowSize(1); writer.write(tablet); closeFile(); // in this case, the value of s2 = 0 at time 10000. 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 54401184c..fabb95731 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 @@ -59,7 +59,7 @@ public void testAddValue() { tablet.addTimestamp(2, 2); tablet.addValue(2, 0, true); - Assert.assertEquals(tablet.rowSize, 3); + Assert.assertEquals(tablet.getRowSize(), 3); Assert.assertTrue((Boolean) tablet.getValue(0, 0)); Assert.assertTrue((Boolean) tablet.getValue(0, 1)); Assert.assertFalse((Boolean) tablet.getValue(1, 0)); @@ -73,10 +73,10 @@ public void testAddValue() { Assert.assertTrue(tablet.bitMaps[1].isMarked(2)); tablet.addTimestamp(9, 9); - Assert.assertEquals(10, tablet.rowSize); + Assert.assertEquals(10, tablet.getRowSize()); tablet.reset(); - Assert.assertEquals(0, tablet.rowSize); + Assert.assertEquals(0, tablet.getRowSize()); Assert.assertTrue(tablet.bitMaps[0].isAllMarked()); Assert.assertTrue(tablet.bitMaps[0].isAllMarked()); Assert.assertTrue(tablet.bitMaps[0].isAllMarked()); @@ -141,7 +141,7 @@ public void testSerializationAndDeSerializationWithMoreData() { final int rowSize = 1000; final Tablet tablet = new Tablet(deviceId, measurementSchemas); - tablet.rowSize = rowSize; + tablet.setRowSize(rowSize); tablet.initBitMaps(); for (int i = 0; i < rowSize - 1; i++) { tablet.addTimestamp(i, i); @@ -210,7 +210,7 @@ public void testSerializationAndDeSerializationNull() { final int rowSize = 1000; final Tablet tablet = new Tablet(deviceId, measurementSchemas); - tablet.rowSize = rowSize; + tablet.setRowSize(rowSize); tablet.initBitMaps(); for (int i = 0; i < rowSize; i++) { tablet.addTimestamp(i, i);