InfluxCommunity/influxdb3-java

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

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 PointValues structure with client.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);
    });
}
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) and p.getField("location", String.class) should be changed to p.getTimestamp() and p.getTag("location").

Actual behavior

  • As I said above, p.getField("time", LocalDateTime.class) and p.getField("location", String.class) will actually just get null.

Additional info

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 .