File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
examples/src/main/java/com/influxdb/v3 Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 2121 */
2222package com .influxdb .v3 ;
2323
24+ import java .util .UUID ;
2425import java .util .stream .Stream ;
2526
2627import 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}
You can’t perform that action at this time.
0 commit comments