Skip to content

Commit

Permalink
modify example
Browse files Browse the repository at this point in the history
  • Loading branch information
shuwenwei committed Dec 24, 2024
1 parent 609baf1 commit 59462d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public static void main(String[] args) throws IOException {
tableName,
Arrays.asList(
new ColumnSchemaBuilder()
.name("id1")
.name("tag1")
.dataType(TSDataType.STRING)
.category(Tablet.ColumnCategory.TAG)
.build(),
new ColumnSchemaBuilder()
.name("id2")
.name("tag2")
.dataType(TSDataType.STRING)
.category(Tablet.ColumnCategory.TAG)
.build(),
Expand All @@ -77,14 +77,14 @@ public static void main(String[] args) throws IOException {

Tablet tablet =
new Tablet(
Arrays.asList("id1", "id2", "s1", "s2"),
Arrays.asList("tag1", "tag2", "s1", "s2"),
Arrays.asList(
TSDataType.STRING, TSDataType.STRING, TSDataType.INT32, TSDataType.BOOLEAN));
for (int row = 0; row < 5; row++) {
long timestamp = row;
tablet.addTimestamp(row, timestamp);
tablet.addValue(row, "id1", "id1_filed_1");
tablet.addValue(row, "id2", "id2_filed_1");
tablet.addValue(row, "tag1", "tag1_value_1");
tablet.addValue(row, "tag2", "tag2_value_1");
tablet.addValue(row, "s1", row);
// null value
// tablet.addValue(row, "s2", true);
Expand All @@ -93,11 +93,11 @@ public static void main(String[] args) throws IOException {
long timestamp = row;
tablet.addTimestamp(row, timestamp);

// id1 column
tablet.addValue(row, 0, "id1_field_2");
// tag1 column
tablet.addValue(row, 0, "tag1_value_2");

// id2 column
tablet.addValue(row, 1, "id1_field_2");
// tag2 column
tablet.addValue(row, 1, "tag1_value_2");

// s1 column: null value
// tablet.addValue(row, 2, row);
Expand All @@ -123,7 +123,7 @@ public static void main(String[] args) throws IOException {
// file is a required parameter
try (ITsFileReader reader = new TsFileReaderBuilder().file(f).build();
ResultSet resultSet =
reader.query(tableName, Arrays.asList("id1", "id2", "s1", "s2"), 2, 8)) {
reader.query(tableName, Arrays.asList("tag1", "tag2", "s1", "s2"), 2, 8)) {
// first column is Time
ResultSetMetadata metadata = resultSet.getMetadata();
System.out.println(metadata);
Expand All @@ -134,17 +134,17 @@ public static void main(String[] args) throws IOException {
System.out.println(sj.toString());
while (resultSet.next()) {
// columnIndex starts from 1
// Time id1 id2 s1 s2
// Time tag1 tag2 s1 s2
Long timeField = resultSet.getLong("Time");
String id1Field = resultSet.isNull("id1") ? null : resultSet.getString("id1");
String id2Field = resultSet.isNull("id2") ? null : resultSet.getString("id2");
String tag1 = resultSet.isNull("tag1") ? null : resultSet.getString("tag1");
String tag2 = resultSet.isNull("tag2") ? null : resultSet.getString("tag2");
Integer s1Field = resultSet.isNull("s1") ? null : resultSet.getInt(4);
Boolean s2Field = resultSet.isNull("s2") ? null : resultSet.getBoolean(5);
sj = new StringJoiner(" ");
System.out.println(
sj.add(timeField + "")
.add(id1Field)
.add(id2Field)
.add(tag1)
.add(tag2)
.add(s1Field + "")
.add(s2Field + "")
.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public static void main(String[] args) throws IOException {
tableName,
Arrays.asList(
new ColumnSchemaBuilder()
.name("id1")
.name("tag1")
.dataType(TSDataType.STRING)
.category(Tablet.ColumnCategory.TAG)
.build(),
new ColumnSchemaBuilder()
.name("id2")
.name("tag2")
.dataType(TSDataType.STRING)
.category(Tablet.ColumnCategory.TAG)
.build(),
Expand All @@ -81,14 +81,14 @@ public static void main(String[] args) throws IOException {
.build()) {
Tablet tablet =
new Tablet(
Arrays.asList("id1", "id2", "s1", "s2"),
Arrays.asList("tag1", "tag2", "s1", "s2"),
Arrays.asList(
TSDataType.STRING, TSDataType.STRING, TSDataType.INT32, TSDataType.BOOLEAN));
for (int row = 0; row < 5; row++) {
long timestamp = row;
tablet.addTimestamp(row, timestamp);
tablet.addValue(row, "id1", "id1_filed_1");
tablet.addValue(row, "id2", "id2_filed_1");
tablet.addValue(row, "tag1", "tag1_value_1");
tablet.addValue(row, "tag2", "tag2_value_1");
tablet.addValue(row, "s1", row);
tablet.addValue(row, "s2", true);
}
Expand All @@ -102,11 +102,11 @@ public static void main(String[] args) throws IOException {
// rowSize may be changed after addTimestamp
tablet.addTimestamp(rowIndex, timestamp);

// id1 column
tablet.addValue(rowIndex, 0, "id1_field_2");
// tag1 column
tablet.addValue(rowIndex, 0, "tag1_value_2");

// id2 column
tablet.addValue(rowIndex, 1, "id2_field_2");
// tag2 column
tablet.addValue(rowIndex, 1, "tag2_value_2");

// s1 column
tablet.addValue(rowIndex, 2, 1);
Expand Down

0 comments on commit 59462d9

Please sign in to comment.