influxdata/influxdb-client-java

FluxResultMapper toPojo not setting values to fields

kalicja opened this issue · 2 comments

Steps to reproduce:
List the minimal actions needed to reproduce the behavior.

  1. Create POJO ie:
    `@Measurement(name = "measure_name")
    public class SampleMeasure{

    @column(timestamp = true)
    private Instant time;

    @column(tag = true)
    private String tag;

    @column
    private String field1;

    @column
    private String field2;`

  2. Write to influx
    Listm =new ArrayList() .....
    writeApi.writeMeasurements(bucket, organization, WritePrecision.MS, m);

  3. Read all with flux query
    Flux fluxQuery = Flux.from(bucket) .range(-356L, ChronoUnit.DAYS) .filter(Restrictions.and(Restrictions.measurement().equal('measure_name'))); return influxDBClient.getQueryApi().query(fluxQuery.toString(),SampleMeasure.class);

Expected behavior:
returned List of SampleMeasure objects with field1, field2 set

Actual behavior:
returned List of SampleMeasure objects with field1, field2 null, tags and time is set correctly

Specifications:

  • Client Version: 5.0.0
  • InfluxDB Version: 2.2.0
  • JDK Version: 17
  • Platform: win 11

Hi @kalicja,

thanks for using our client.

You have to use pivot() function.

Flux fluxQuery = Flux
        .from(bucket)
        .range(-356L, ChronoUnit.DAYS)
        .filter(Restrictions.and(Restrictions.measurement().equal("measure_name")))
        .pivot()
            .withRowKey(new String[]{"_time"})
            .withColumnKey(new String[]{"_field"})
            .withValueColumn("_value");

Regards

HI @bednar
thx a lot, it works :D, it may be worth of adding it to examples?