Documentation is misleading about the use of `com.influxdb.v3.client.PointValues`
Closed this issue · 2 comments
Specifications
- Client Version:
1.0.0 - InfluxDB Version: Docker Image
quay.io/influxdb/influxdb3-core:911ba92ab4133e75fe2a420e16ed9cb4cf32196f - Platform:
InfluxDB 3 Core
Code sample to reproduce problem
- For https://github.com/InfluxCommunity/influxdb3-java/blob/ec43aea9065da168c00d2fd9ac04bb6b3b1ac07d/README.md , it mentions,
to insert data, you can use code like this:
//
// Write by Point
//
Point point = Point.measurement("temperature")
.setTag("location", "west")
.setField("value", 55.15)
.setTimestamp(Instant.now().minusSeconds(-10));
client.writePoint(point);or use
PointValuesstructure withclient.queryPoints:
String sql1 = "select time,location,value from temperature order by time desc limit 10";
try (Stream<PointValues> stream = client.queryPoints(sql1, QueryOptions.DEFAULTS)) {
stream.forEach(
(PointValues p) -> {
var time = p.getField("time", LocalDateTime.class);
var location = p.getField("location", String.class);
var value = p.getField("value", Double.class);
System.out.printf("| %-8s | %-8s | %-30s |%n", location, value, time);
});
}-
p.getField("time", LocalDateTime.class)andp.getField("location", String.class)will actually just getnull. -
I created a minimal reproducible unit test at https://github.com/linghengqian/influxdb-3-core-jdbc-test/blob/master/src/test/java/io/github/linghengqian/influxdb3java/PointValuesTest.java .
-
Verified unit test under Ubuntu 22.04.5 LTS with
SDKMAN!andDocker CE.
sdk install java 21.0.6-ms
git clone git@github.com:linghengqian/influxdb-3-core-jdbc-test.git
cd ./influxdb-3-core-jdbc-test/
sdk use java 21.0.6-ms
./mvnw -T 1C clean test@Testcontainers
public class PointValuesTest {
private final Instant magicTime = Instant.now().minusSeconds(10);
@Container
private final GenericContainer<?> container = new GenericContainer<>("quay.io/influxdb/influxdb3-core:911ba92ab4133e75fe2a420e16ed9cb4cf32196f")
.withCommand("serve --node-id local01 --object-store file --data-dir /home/influxdb3/.influxdb3")
.withExposedPorts(8181);
@Test
void test() throws Exception {
try (InfluxDBClient client = InfluxDBClient.getInstance(
"http://" + container.getHost() + ":" + container.getMappedPort(8181),
null,
"mydb")) {
writeData(client);
queryData(client);
}
}
private void writeData(InfluxDBClient client) {
Point point = Point.measurement("home")
.setTag("location", "London")
.setField("value", 30.01)
.setTimestamp(magicTime);
client.writePoint(point);
}
private void queryData(InfluxDBClient client) {
try (Stream<PointValues> stream = client.queryPoints("select time,location,value from home order by time desc limit 10",
QueryOptions.DEFAULTS)) {
List<PointValues> list = stream.toList();
assertThat(list.size(), is(1));
PointValues p = list.getFirst();
assertThat(p.getField("time", LocalDateTime.class), nullValue());
assertThat(p.getField("location", String.class), nullValue());
assertThat(p.getField("value", Double.class), is(30.01));
assertThat(p.getTag("location"), is("London"));
assertThat(p.getTimestamp(), is(NanosecondConverter.convert(magicTime, WritePrecision.NS)));
}
}
}Expected behavior
- Uses of
p.getField("time", LocalDateTime.class)andp.getField("location", String.class)should be changed top.getTimestamp()andp.getTag("location").
Actual behavior
- As I said above,
p.getField("time", LocalDateTime.class)andp.getField("location", String.class)will actually just getnull.
Additional info
- Early investigations came from the unit tests on the https://github.com/linghengqian/influxdb-3-core-jdbc-test side.
Hi @linghengqian,
thanks for report this.
Is this something you would be willing to help with? All PR is welcome and we will be happy to review your submission.
Best Regards
Hi @linghengqian,
thanks for report this.
Is this something you would be willing to help with? All PR is welcome and we will be happy to review your submission.
Best Regards
- I have opened #223 .