Skip to content

Commit 9008c68

Browse files
feat: update example
1 parent 01a83a2 commit 9008c68

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/src/main/java/com/influxdb/v3/ProxyExample.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package com.influxdb.v3;
2323

24+
import java.util.UUID;
2425
import java.util.stream.Stream;
2526

2627
import com.influxdb.v3.client.InfluxDBClient;
@@ -47,14 +48,24 @@ public static void main(final String[] args) throws Exception {
4748
.build();
4849

4950
InfluxDBClient influxDBClient = InfluxDBClient.getInstance(clientConfig);
50-
Point point = Point.measurement("Home")
51+
String testId = UUID.randomUUID().toString();
52+
Point point = Point.measurement("My_Home")
5153
.setTag("room", "Kitchen")
5254
.setField("temp", 12.7)
53-
.setField("hum", 37);
55+
.setField("hum", 37)
56+
.setField("testId", testId);
5457
influxDBClient.writePoint(point);
5558

56-
try (Stream<PointValues> stream = influxDBClient.queryPoints("SELECT * FROM Home")) {
57-
stream.findFirst().ifPresent(System.out::println);
59+
String query = String.format("SELECT * FROM \"My_Home\" WHERE \"testId\" = '%s'", testId);
60+
try (Stream<PointValues> stream = influxDBClient.queryPoints(query)) {
61+
stream.findFirst().ifPresent(values -> {
62+
assert values.getTimestamp() != null;
63+
System.out.printf("room[%s]: %s, temp: %3.2f, hum: %d",
64+
new java.util.Date(values.getTimestamp().longValue() / 1000000),
65+
values.getTag("room"),
66+
(Double) values.getField("temp"),
67+
(Long) values.getField("hum"));
68+
});
5869
}
5970
}
6071
}

0 commit comments

Comments
 (0)