I am trying to update a record (only the field values) using influxdb java client.
Specifically, I am using InfluxDBMapper to store the queried result, I update the POJO with new field values and build the PointBuilder as below:
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress);
I then use the influx.write() to send it to the DB. Batching is enabled. However I get 400 error and the values are not updated in the DB.
Is this not the right way to update values?
Update:
I think I found the reason. My DBs are with precision of Milliseconds. I have set the TimeUnit correctly for the POJO too. However when I Build the Point as above, it does not take into consideration the TimeUnit set by me and defaults to Nanoseconds.
This is probably the reason it fails.
I changed to below lines but it still does not change the time unit:
final long time = reqInProgress.getTime().getLong(ChronoField.MILLI_OF_SECOND);
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress).time(time, TimeUnit.MILLISECONDS);
So I fixed my problem. Seems like using write is not the way to go when using influxDBMapper and instead influxDBMapper.save() should be used.
The reason being when write is used, time is added as a field in the line protocol and this is invalid in influxDB.
IMHO the client library should take care of converting the time appropriately especially if we annotate it as a time column.
@mns and @Anaisdg
The OP is very similar, if not exact, to what I faced. Im using Influx db version 1.5 with java client 2.15.
I also have a POJO to map tags and fields. But for some reason InfluxDBMapper.save(T model) didnt work for me.
Fetching results from db were correctly mapped to POJO. Here’s a snapshot of what I was doing:
Get point from influx and map it to MyPOJO.
Update it.
Save the update with InfluxDBMapper.save(udpatedPOJO).
But for some reason the update never reflected in influx. I had to manually build a Point and then write() to make it show up in Influx.
Im wondering how save() worked for you but not in my case.