From f3d054ff431cf4a6068e4ccc96e520fac00c3c4d Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Thu, 28 Nov 2024 10:50:31 +0800 Subject: [PATCH] fix example --- .../src/main/java/org/apache/tsfile/TsFileRead.java | 7 +++++-- .../tsfile/TsFileWriteAlignedWithTSRecord.java | 6 +++--- .../org/apache/tsfile/TsFileWriteWithTSRecord.java | 6 +++--- .../org/apache/tsfile/TsFileWriteWithTablet.java | 13 +++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/java/examples/src/main/java/org/apache/tsfile/TsFileRead.java b/java/examples/src/main/java/org/apache/tsfile/TsFileRead.java index 64ef6f99e..5b520fc6c 100644 --- a/java/examples/src/main/java/org/apache/tsfile/TsFileRead.java +++ b/java/examples/src/main/java/org/apache/tsfile/TsFileRead.java @@ -19,6 +19,7 @@ package org.apache.tsfile; +import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.read.TsFileReader; import org.apache.tsfile.read.TsFileSequenceReader; import org.apache.tsfile.read.common.Path; @@ -97,7 +98,8 @@ public static void main(String[] args) throws IOException { // value filter : device_1.sensor_2 <= 20, should select 1 2 4 6 7 IExpression valueFilter = - new SingleSeriesExpression(new Path(DEVICE_1, SENSOR_2, true), ValueFilterApi.ltEq(20L)); + new SingleSeriesExpression( + new Path(DEVICE_1, SENSOR_2, true), ValueFilterApi.ltEq(1, 20L, TSDataType.INT64)); queryAndPrint(paths, readTsFile, valueFilter); // time filter : 4 <= time <= 10, value filter : device_1.sensor_3 >= 20, should select 4 7 8 @@ -106,7 +108,8 @@ public static void main(String[] args) throws IOException { new GlobalTimeExpression(TimeFilterApi.gtEq(4L)), new GlobalTimeExpression(TimeFilterApi.ltEq(10L))); valueFilter = - new SingleSeriesExpression(new Path(DEVICE_1, SENSOR_3, true), ValueFilterApi.gtEq(20L)); + new SingleSeriesExpression( + new Path(DEVICE_1, SENSOR_3, true), ValueFilterApi.gtEq(2, 20L, TSDataType.INT64)); IExpression finalFilter = BinaryExpression.and(timeFilter, valueFilter); queryAndPrint(paths, readTsFile, finalFilter); } diff --git a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteAlignedWithTSRecord.java b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteAlignedWithTSRecord.java index f7d1bc7b4..3e4c74486 100644 --- a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteAlignedWithTSRecord.java +++ b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteAlignedWithTSRecord.java @@ -91,18 +91,18 @@ private static void writeAligned( throws IOException, WriteProcessException { for (long time = startTime; time < rowSize + startTime; time++) { // construct TsRecord - TSRecord tsRecord = new TSRecord(time, deviceId); + TSRecord tsRecord = new TSRecord(deviceId, time); for (IMeasurementSchema schema : schemas) { tsRecord.addTuple( DataPoint.getDataPoint( schema.getType(), - schema.getMeasurementId(), + schema.getMeasurementName(), Objects.requireNonNull(DataGenerator.generate(schema.getType(), (int) startValue)) .toString())); startValue++; } // write - tsFileWriter.writeAligned(tsRecord); + tsFileWriter.writeRecord(tsRecord); } } } diff --git a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTSRecord.java b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTSRecord.java index 79f9fd527..42e244247 100644 --- a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTSRecord.java +++ b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTSRecord.java @@ -87,18 +87,18 @@ private static void write( throws IOException, WriteProcessException { for (long time = startTime; time < rowSize + startTime; time++) { // construct TsRecord - TSRecord tsRecord = new TSRecord(time, deviceId); + TSRecord tsRecord = new TSRecord(deviceId, time); for (IMeasurementSchema schema : schemas) { tsRecord.addTuple( DataPoint.getDataPoint( schema.getType(), - schema.getMeasurementId(), + schema.getMeasurementName(), Objects.requireNonNull(DataGenerator.generate(schema.getType(), (int) startValue)) .toString())); startValue++; } // write - tsFileWriter.write(tsRecord); + tsFileWriter.writeRecord(tsRecord); } } } diff --git a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTablet.java b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTablet.java index 3ab95a187..bb0293a52 100644 --- a/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTablet.java +++ b/java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTablet.java @@ -26,6 +26,7 @@ import org.apache.tsfile.read.common.Path; import org.apache.tsfile.write.TsFileWriter; import org.apache.tsfile.write.record.Tablet; +import org.apache.tsfile.write.schema.IMeasurementSchema; import org.apache.tsfile.write.schema.MeasurementSchema; import org.slf4j.Logger; @@ -91,23 +92,23 @@ private static void writeWithTablet( long sensorNum = schemas.size(); for (long r = 0; r < rowNum; r++, startValue++) { - int row = tablet.rowSize++; + int row = tablet.getRowSize(); timestamps[row] = startTime++; for (int i = 0; i < sensorNum; i++) { tablet.addValue( - schemas.get(i).getMeasurementId(), + schemas.get(i).getMeasurementName(), row, DataGenerator.generate(schemas.get(i).getType(), (int) r)); } // write - if (tablet.rowSize == tablet.getMaxRowNumber()) { - tsFileWriter.write(tablet); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + tsFileWriter.writeTree(tablet); tablet.reset(); } } // write - if (tablet.rowSize != 0) { - tsFileWriter.write(tablet); + if (tablet.getRowSize() != 0) { + tsFileWriter.writeTree(tablet); tablet.reset(); } }