Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
8d89f4d
Check blank column name or table name (#471)
shuwenwei Apr 23, 2025
4b75866
Optimizations regarding chunk metadata sort & timeseries metadata ser…
jt2594838 Apr 23, 2025
b385b4f
Remove redundant conversion in TableResultSet (#473)
jt2594838 Apr 25, 2025
73ac55f
Fix CPP TsFile query with time filter error (#474)
HTHou Apr 27, 2025
c731ba0
add switch to disable native lz4 (#480)
jt2594838 Apr 29, 2025
4145395
Fix float RLBE encoding loss of precision (#484)
HTHou May 8, 2025
217cc3c
Add flush method for tsfile python writer (#487)
ycycse May 9, 2025
d2119c1
add table/column schema check. (#488)
ColinLeeo May 12, 2025
e795637
delete parameter encrypt_flag (#491)
zhujt20 May 12, 2025
6f08fb1
Colin fix config (#493)
ColinLeeo May 13, 2025
14cefc9
fix data lossing when page num exceed 1. (#495)
ColinLeeo May 15, 2025
cc8f363
Colin fix config (#472)
ColinLeeo May 19, 2025
dd603b4
Bump setuptools from 70.0.0 to 78.1.1 in /python (#497)
dependabot[bot] May 20, 2025
3a688ee
Add TsFileLastReader for retrieving last points in a TsFile (#498)
jt2594838 May 23, 2025
1856572
Update release information of TsFile v2.0.3 (#505)
HTHou Jun 3, 2025
a5424d3
Same name (case insensitive) in tablet / table. (#490)
ColinLeeo Jun 4, 2025
6672d2d
Fix (#508)
Caideyipi Jun 9, 2025
a71b8d4
fix minus encode and decode. (#511)
ColinLeeo Jun 12, 2025
7859080
Zjt/encrypt key from environment (#512)
zhujt20 Jun 12, 2025
2995362
Fix npe when closing a last reader that have not been used (#513)
jt2594838 Jun 16, 2025
6df6112
The TsFile-CPP query interface now validates column names before quer…
761417898 Jun 18, 2025
c501bf4
Resolved case sensitivity issue when reading column names. (#517)
761417898 Jun 18, 2025
af2a7ee
Fix tag empty error and disorder timestamp. (#489)
ColinLeeo Jun 19, 2025
caa77ac
[Java/C++/C] Resolved case sensitivity issue when reading column name…
761417898 Jun 19, 2025
58fa12f
fix read from iotdb data. (#520)
ColinLeeo Jun 20, 2025
04eb621
Fix bloom filter error.
ColinLeeo Jun 20, 2025
09015fa
[CPP]Fix/multi fileds column (#522)
761417898 Jun 24, 2025
de166a7
Support set default compression by data type (#523)
jt2594838 Jun 24, 2025
d2a906e
Fixes the issue where data with only timestamps could not be inserted…
ColinLeeo Jun 27, 2025
ed5b5dc
The column names in the addValue interface are case-insensitive (#526)
761417898 Jun 27, 2025
af0ec13
Use spotless to format CPP code (#528)
HTHou Jul 1, 2025
e7bdcad
fix some warning while compiling. (#527)
ColinLeeo Jul 2, 2025
6554a18
Correct the memroy calculation of BinaryColumnBuilder
JackieTien97 Jul 3, 2025
a2da0c9
[maven-release-plugin] prepare release v2.1.0
ColinLeeo Jul 4, 2025
efdba35
Revert "[maven-release-plugin] prepare release v2.1.0" (#533)
ColinLeeo Jul 4, 2025
7510d94
Fetch max tsblock line number each time from TSFileConfig
JackieTien97 Jul 7, 2025
c32e893
AbstractAlignedTimeSeriesMetadata.typeMatch always return true (#538)
shuwenwei Jul 8, 2025
4909442
Implement datatype TIMESTAMP BLOB TEXT DATE (#532)
761417898 Jul 9, 2025
a8e48ad
Ignore the null value passed in the Tablet.addValue method (#540)
shuwenwei Jul 9, 2025
110a5a2
Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.18.0 in /java …
dependabot[bot] Jul 14, 2025
490d521
Update version info for tsfile v2.1.0 (#544)
ColinLeeo Jul 15, 2025
838d290
Implement extract time filters
Wei-hao-Li Jul 16, 2025
956d598
implement RLE DICTIONART ZIGZAG codec (#542)
761417898 Jul 17, 2025
d3eb61a
Init all series writer for AlignedChunkGroupWriter
shuwenwei Jul 18, 2025
04bbc0a
Check max tsfile version
shuwenwei Jul 21, 2025
898f1a6
include common in tsfile with shade (#510)
Inky19 Jul 22, 2025
ae3e8c8
Implement extract value filters
Wei-hao-Li Jul 22, 2025
ee647cb
fix wrong Private-Package declaration (#556)
Inky19 Jul 23, 2025
f1dad36
Feature/cpp codec sprintz (#553)
761417898 Jul 23, 2025
965f487
Avoid repeated calculation of shallow size of map
shuwenwei Jul 29, 2025
f3345b9
Refactor UnknownType to extend AbstractType
FearfulTomcat27 Jul 29, 2025
9ef4709
Add Tablet.append (#562)
jt2594838 Jul 30, 2025
f54f8b6
Provides complete implementation of all TagFilter operations
761417898 Aug 12, 2025
1dff37b
Add methods for RamUsageEstimator
shuwenwei Aug 12, 2025
b970e1f
implement new java writing interface for tree model
761417898 Aug 14, 2025
38a847d
generate main key (#519)
zhujt20 Aug 14, 2025
949a7a5
reduce zero-fill overhead on BitMap creation (#572)
luoluoyuyu Aug 15, 2025
858239f
Update release information after v2.1.1 released (#574)
HTHou Aug 18, 2025
95dbf6a
Feature/codec/camel (#560)
761417898 Aug 18, 2025
616e844
implement v4 tree-model read interface
761417898 Aug 18, 2025
c9838b0
Adjusted the sequence of measurements
761417898 Aug 18, 2025
94d5e06
Add licenses
761417898 Aug 18, 2025
550c482
Add support for alter column datatype (#567)
zerolbsony Aug 20, 2025
a426db2
Add v4 interface example
761417898 Aug 21, 2025
988beea
Add v4 PerformanceTest
761417898 Aug 22, 2025
01be82e
feat: add markRange / unmarkRange / merge for high-performance bit ma…
luoluoyuyu Aug 25, 2025
674a65c
perf: Optimize aligned object memory size calculation (#577)
luoluoyuyu Aug 27, 2025
a5fee93
[CPP/C] implement default encoding/compression configuration interfac…
761417898 Sep 1, 2025
dcdbcf8
Bump actions/first-interaction from 1.3.0 to 3.0.0 (#586)
dependabot[bot] Sep 3, 2025
fd1adb8
Bump actions/setup-java from 4 to 5 (#584)
dependabot[bot] Sep 3, 2025
5132d99
Alter column other type to string type (#588)
zerolbsony Sep 3, 2025
1dce1b0
Bump actions/checkout from 4 to 5 (#583)
dependabot[bot] Sep 4, 2025
39e55a3
Fix camel encoding error message and add check for each datatypes of …
HTHou Sep 18, 2025
83250e3
Modify the TsFileSequenceReaderTimeseriesMetadataIterator next functi…
luoluoyuyu Sep 28, 2025
c2a2937
add encrypt param for all the write/read struct initialization (#601)
zhujt20 Oct 10, 2025
1e5e7ef
Merge branch 'develop' into new_java_interfaces
761417898 Oct 16, 2025
84444eb
fix TableResultSet.Iterator unittest
761417898 Oct 16, 2025
12b4ce9
add license
761417898 Oct 17, 2025
a6d5696
spotless:apply
761417898 Oct 17, 2025
e1d0734
fix MeasurementSchemaBuilder getCompressor()
761417898 Oct 27, 2025
8ff0900
removed unused IDeviceID.toString()
761417898 Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions java/examples/src/main/java/org/apache/tsfile/v4/TagFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.tsfile.v4;

import org.apache.tsfile.enums.ColumnCategory;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.ColumnSchemaBuilder;
import org.apache.tsfile.file.metadata.TableSchema;
import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.filter.factory.TagFilterBuilder;
import org.apache.tsfile.read.query.dataset.ResultSet;
import org.apache.tsfile.read.v4.ITsFileReader;
import org.apache.tsfile.read.v4.TsFileReaderBuilder;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.v4.ITsFileWriter;
import org.apache.tsfile.write.v4.TsFileWriterBuilder;

import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;

public class TagFilterExample {

public static void main(String[] args) throws Exception {
String path = "tag_filter_example.tsfile";
File f = new File(path);
if (f.exists()) {
Files.delete(f.toPath());
}

// Define table schema
TableSchema schema =
new TableSchema(
"t1",
Arrays.asList(
new ColumnSchemaBuilder()
.name("id1")
.dataType(TSDataType.STRING)
.category(ColumnCategory.TAG)
.build(),
new ColumnSchemaBuilder()
.name("id2")
.dataType(TSDataType.STRING)
.category(ColumnCategory.TAG)
.build(),
new ColumnSchemaBuilder()
.name("s1")
.dataType(TSDataType.BOOLEAN)
.category(ColumnCategory.FIELD)
.build(),
new ColumnSchemaBuilder()
.name("s2")
.dataType(TSDataType.BOOLEAN)
.category(ColumnCategory.FIELD)
.build()));

// Prepare tablet for writing data
Tablet tablet =
new Tablet(
Arrays.asList("id1", "id2", "s1", "s2"),
Arrays.asList(
TSDataType.STRING, TSDataType.STRING, TSDataType.BOOLEAN, TSDataType.BOOLEAN));

// Row 0
tablet.addTimestamp(0, 0);
tablet.addValue(0, "id1", "id_01");
tablet.addValue(0, "id2", "name_01");
tablet.addValue(0, "s1", true);
tablet.addValue(0, "s2", false);

// Row 1
tablet.addTimestamp(1, 1);
tablet.addValue(1, "id1", "id_02");
tablet.addValue(1, "id2", "name_02");
tablet.addValue(1, "s1", false);
tablet.addValue(1, "s2", true);

// Row 2
tablet.addTimestamp(2, 2);
tablet.addValue(2, "id1", "id_03");
tablet.addValue(2, "id2", "name_03");
tablet.addValue(2, "s1", true);
tablet.addValue(2, "s2", true);

// Row 3
tablet.addTimestamp(3, 3);
tablet.addValue(3, "id1", "id_04");
tablet.addValue(3, "id2", "name_04");
tablet.addValue(3, "s1", false);
tablet.addValue(3, "s2", false);

// Write tablet to TsFile
try (ITsFileWriter writer = new TsFileWriterBuilder().file(f).tableSchema(schema).build()) {
writer.write(tablet);
}

// ---------------- TagFilter Examples ----------------
TagFilterBuilder filterBuilder = new TagFilterBuilder(schema);

// eq
queryWithFilter(f, schema, filterBuilder.eq("id1", "id_02"), "eq(id1 = id_02)");

// neq
queryWithFilter(f, schema, filterBuilder.neq("id1", "id_02"), "neq(id1 != id_02)");

// lt
queryWithFilter(f, schema, filterBuilder.lt("id1", "id_03"), "lt(id1 < id_03)");

// lteq
queryWithFilter(f, schema, filterBuilder.lteq("id1", "id_03"), "lteq(id1 <= id_03)");

// gt
queryWithFilter(f, schema, filterBuilder.gt("id1", "id_02"), "gt(id1 > id_02)");

// gteq
queryWithFilter(f, schema, filterBuilder.gteq("id1", "id_02"), "gteq(id1 >= id_02)");

// betweenAnd
queryWithFilter(
f,
schema,
filterBuilder.betweenAnd("id1", "id_02", "id_03"),
"betweenAnd(id1 between id_02 and id_03)");

// notBetweenAnd
queryWithFilter(
f,
schema,
filterBuilder.notBetweenAnd("id1", "id_02", "id_03"),
"notBetweenAnd(id1 not between id_02 and id_03)");

// and
queryWithFilter(
f,
schema,
filterBuilder.and(filterBuilder.gteq("id1", "id_02"), filterBuilder.lteq("id1", "id_03")),
"and(gteq(id1,id_02), lteq(id1,id_03))");

// or
queryWithFilter(
f,
schema,
filterBuilder.or(filterBuilder.eq("id1", "id_01"), filterBuilder.eq("id1", "id_04")),
"or(eq(id1,id_01), eq(id1,id_04))");

// not
queryWithFilter(
f, schema, filterBuilder.not(filterBuilder.eq("id1", "id_02")), "not(eq(id1,id_02))");

// regExp
queryWithFilter(
f, schema, filterBuilder.regExp("id1", "id_0[23]"), "regExp(id1 matches id_0[23])");

// notRegExp
queryWithFilter(
f,
schema,
filterBuilder.notRegExp("id1", "id_0[23]"),
"notRegExp(id1 not matches id_0[23])");

// like
queryWithFilter(f, schema, filterBuilder.like("id1", "id_0_"), "like(id1 like id_0_)");

// notLike
queryWithFilter(
f, schema, filterBuilder.notLike("id1", "id_0_"), "notLike(id1 not like id_0_)");
new File(path).delete();
}

/** Helper method to execute a query with a given filter and print results. */
private static void queryWithFilter(File f, TableSchema schema, Object filter, String desc)
throws Exception {
try (ITsFileReader reader = new TsFileReaderBuilder().file(f).build();
ResultSet rs =
reader.query("t1", Arrays.asList("id1", "id2", "s1", "s2"), 0, 3, (Filter) filter)) {

System.out.println("=== Query with TagFilter " + desc + " ===");
while (rs.next()) {
long time = rs.getLong("Time");
String id1 = rs.getString("id1");
String id2 = rs.getString("id2");
Boolean s1 = rs.isNull("s1") ? null : rs.getBoolean("s1");
Boolean s2 = rs.isNull("s2") ? null : rs.getBoolean("s2");

System.out.printf("time=%d, id1=%s, id2=%s, s1=%s, s2=%s%n", time, id1, id2, s1, s2);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.tsfile.v4;

import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.exception.write.WriteProcessException;
import org.apache.tsfile.read.query.dataset.ResultSet;
import org.apache.tsfile.read.query.dataset.ResultSetMetadata;
import org.apache.tsfile.read.v4.ITsFileTreeReader;
import org.apache.tsfile.read.v4.TsFileTreeReaderBuilder;
import org.apache.tsfile.write.record.TSRecord;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.schema.IMeasurementSchema;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.apache.tsfile.write.v4.TsFileTreeWriter;
import org.apache.tsfile.write.v4.TsFileTreeWriterBuilder;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Example for writing and reading TsFile in tree model.
*
* <p>Demonstrates: - Defining schemas for multiple devices - Writing data using both Tablet and
* TSRecord - Reading back with TsFileTreeReader - Retrieving device IDs and schema info - Using
* ResultSet and ResultSetMetadata
*/
public class TsFileTreeReaderExample {

private static final String FILE_PATH = "tree_model_example.tsfile";

public static void main(String[] args) throws IOException {
File file = new File(FILE_PATH);
if (file.exists()) {
file.delete();
}

// Step 1. Generate TsFile with tree writer
generateTestTsFile(file);

List<String> deviceIds = Arrays.asList("d1", "d2");
List<String> measurements = Arrays.asList("s1", "s2");

// Step 2. Build tree reader
try (ITsFileTreeReader treeReader = new TsFileTreeReaderBuilder().file(file).build()) {

// === Basic query by devices and measurements ===

try (ResultSet resultSet =
treeReader.query(deviceIds, measurements, Long.MIN_VALUE, Long.MAX_VALUE)) {

System.out.println("=== Query results ===");
while (resultSet.next()) {
long time = resultSet.getLong(1);
Integer d1s1 = resultSet.isNull("d1.s1") ? null : resultSet.getInt("d1.s1");
Long d1s2 = resultSet.isNull("d1.s2") ? null : resultSet.getLong("d1.s2");
Integer d2s1 = resultSet.isNull("d2.s1") ? null : resultSet.getInt("d2.s1");

System.out.printf("time=%d, d1.s1=%s, d1.s2=%s, d2.s1=%s%n", time, d1s1, d1s2, d2s1);
}
}
// === Retrieve all device IDs ===
List<String> allDeviceIds = treeReader.getAllDeviceIds();
System.out.println("=== All device IDs === " + allDeviceIds);

// === Retrieve schema of device d1 ===
List<MeasurementSchema> schemas = treeReader.getDeviceSchema("d1");
List<String> measurementNames =
schemas.stream().map(IMeasurementSchema::getMeasurementName).collect(Collectors.toList());
System.out.println("=== Schema of d1 === " + measurementNames);

// === ResultSet metadata ===
try (ResultSet resultSet =
treeReader.query(deviceIds, measurements, Long.MIN_VALUE, Long.MAX_VALUE)) {
ResultSetMetadata metadata = resultSet.getMetadata();
System.out.println("=== Metadata columns ===");
for (int i = 1; i <= 4; i++) {
System.out.printf("Column %d: %s%n", i, metadata.getColumnName(i));
}
}
}

// === Iterator-based query example ===
try (ITsFileTreeReader treeReader = new TsFileTreeReaderBuilder().file(file).build()) {

long startTime = Long.MIN_VALUE;
long endTime = Long.MAX_VALUE;

try (ResultSet resultSet = treeReader.query(deviceIds, measurements, startTime, endTime)) {
System.out.println("=== Iterator-based query results ===");
Iterator<TSRecord> recordIterator = resultSet.recordIterator();
int countVal = 0;

while (recordIterator.hasNext()) {
TSRecord record = recordIterator.next();
System.out.println(
"Device: " + record.deviceId.getDeviceID() + ", Timestamp: " + record.time);

if (record.deviceId.getDeviceID().equals("d1")) {
System.out.println(
" Measurement at index 1: "
+ record.dataPointList.get(1).getMeasurementId()
+ " = "
+ record.dataPointList.get(1).getValue());
System.out.println(
" Measurement at index 2: "
+ record.dataPointList.get(2).getMeasurementId()
+ " = "
+ record.dataPointList.get(2).getValue());
} else if (record.deviceId.getDeviceID().equals("d2")) {
System.out.println(
" Measurement at index 1: "
+ record.dataPointList.get(1).getMeasurementId()
+ " = "
+ record.dataPointList.get(1).getValue());
System.out.println(" Measurement at index 2 is null");
} else {
System.out.println(" Unexpected deviceId: " + record.deviceId.getDeviceID());
}

countVal++;
}

System.out.println("Total records iterated: " + countVal);
}
}
new File(FILE_PATH).delete();
}

private static void generateTestTsFile(File file) throws IOException {
try (TsFileTreeWriter writer = new TsFileTreeWriterBuilder().file(file).build()) {
// Define schemas
IMeasurementSchema schema1 = new MeasurementSchema("s1", TSDataType.INT32);
IMeasurementSchema schema2 = new MeasurementSchema("s2", TSDataType.INT64);

// Register schemas for devices
writer.registerTimeseries("d1", schema1);
writer.registerTimeseries("d1", schema2);
writer.registerTimeseries("d2", schema1);

// Write data for device d1 with Tablet
Tablet d1Tablet = new Tablet("d1", Arrays.asList(schema1, schema2));
for (int i = 0; i < 5; i++) {
d1Tablet.addTimestamp(i, i);
d1Tablet.addValue(i, 0, i); // s1
d1Tablet.addValue(i, 1, (long) i); // s2
}
writer.write(d1Tablet);

// Write data for device d2 with TSRecord
for (int i = 0; i < 5; i++) {
TSRecord record = new TSRecord("d2", i);
record.addPoint("s1", i);
writer.write(record);
}
} catch (WriteProcessException e) {
throw new RuntimeException(e);
}
}
}
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.15.0</version>
<version>3.18.0</version>
</dependency>
<dependency>
<groupId>org.lz4</groupId>
Expand Down
Loading