Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
shuwenwei committed Nov 28, 2024
1 parent fcee5e6 commit f3d054f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 5 additions & 2 deletions java/examples/src/main/java/org/apache/tsfile/TsFileRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit f3d054f

Please sign in to comment.