The examples show how to write and read a TsFile file.
<dependencies>
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
All writers below live in src/main/java/org/apache/tsfile/ and can be run from
an IDE or with java -cp <classpath> org.apache.tsfile.<ClassName>.
| Class | Write model | API | Output file |
|---|---|---|---|
TsFileWriteWithTSRecord |
Non-aligned (tree model) | TsFileWriter.registerTimeseries + TSRecord |
Record.tsfile |
TsFileWriteWithTablet |
Non-aligned (tree model) | TsFileWriter.registerTimeseries + Tablet |
Tablet.tsfile |
TsFileWriteAlignedWithTSRecord |
Aligned | TsFileWriter.registerAlignedTimeseries + TSRecord |
alignedRecord.tsfile |
TsFileWriteAlignedWithTablet |
Aligned and non-aligned in one file | registerAlignedTimeseries + registerTimeseries + Tablet |
alignedTablet.tsfile |
TsFileForceAppendWrite |
Non-aligned (tree model) | TsFileWriter.writeRecord in batches |
test.tsfile |
TSRecord is the row-oriented API: one timestamp with a list of data points.
Tablet is the column-oriented batch API and is preferred for volume writes.
The aligned variants require every measurement of a device to share the same
timestamp column.
TsFileRead queries test.tsfile, so run TsFileForceAppendWrite first to
generate it. The example shows a plain query, a time-range filter
(GlobalTimeExpression with TimeFilterApi), a value filter
(SingleSeriesExpression with ValueFilterApi), and a combined filter.
TsFileSequenceRead scans a TsFile from head to tail and prints its physical
layout: magic strings, metadata positions, chunk groups, chunks, and pages. Pass
the file to scan as the first argument; it defaults to test.tsfile.
The v4/ package contains examples for the newer reader/writer APIs:
ITsFileReaderAndITsFileWriter, WriteTabletWithITsFileWriter,
TsFileTreeReaderExample, and TagFilterExample.
For detail, please refer to https://github.com/apache/tsfile/blob/develop/README.md.