Problem with batch insertion and null values
Hi, I had a problem with the insertion via the java client. I have some data that I retrieve from the DB, and I loop over the result set to create Influx Points containing some tags and some fields. If one of the field value is null, I add it in any case to my Point as a field. If all field values are null, I skip the entry.
I use batch insertion capabilities of your client API.
Now here is what happened; for the first bunches of insertions, everything goes fine... Then at a certain moment I have some null values appearing in one (or more) fields. When this occurs the batch insertion fails, with this message:
java.lang.RuntimeException: {"error":"partial write:\nunable to parse 'LAR_DCS_HV_Barrel,CHANNEL_ID=182000 R_IMEAS=0.0,R_STAT=0.0, 1490108905000000000': invalid field format\nunable to parse 'LAR_DCS_HV_Barrel,CHANNEL_ID=186006 R_IMEAS=0.0,R_STAT=0.0, 1490108905000000000': invalid field format\nunable to parse ..... etc
I activated the FULL logging level to see what was going on, and in fact I noticed that for "normal" Points here is what the http call seems to send: 2017-03-22 20:16:34.057 INFO 2598 --- [pool-9-thread-1] okhttp3.OkHttpClient : LAR_DCS_HV_Barrel,CHANNEL_ID=85007 R_IMEAS=0.0,R_STAT=0.0,R_VMEAS=0.0 1481561103000000000 LAR_DCS_HV_Barrel,CHANNEL_ID=86000 R_IMEAS=0.0,R_STAT=0.0,R_VMEAS=0.0 1481561103000000000 LAR_DCS_HV_Barrel,CHANNEL_ID=86001 R_IMEAS=0.0,R_STAT=0.0,R_VMEAS=0.0 1481561103000000000
while for Points with some null fields I have: 2017-03-22 20:17:45.893 INFO 2598 --- [ool-15-thread-1] okhttp3.OkHttpClient : LAR_DCS_HV_Barrel,CHANNEL_ID=82005 R_IMEAS=-0.00029999998514540493, 1488182401000000000 LAR_DCS_HV_Barrel,CHANNEL_ID=82006 R_IMEAS=-0.00029999998514540493, 1488182401000000000 LAR_DCS_HV_Barrel,CHANNEL_ID=82007 R_IMEAS=-0.00009999999747378752, 1488182401000000000 LAR_DCS_HV_Barrel,CHANNEL_ID=83001 R_IMEAS=-0.0005999999702908099, 1488182401000000000
As you can see there is a comma right before the timestamp...which seems not correct.
I tried to validate this hypothesis by putting a 0. instead of null values, and everything worked fine.
I do not know if it is something that InfluxDB does not accept (insertion of nulls), or if it is an API problem. I am using version 2.5 of the API. compile group: 'org.influxdb', name: 'influxdb-java', version: '2.5'
Thanks for any hint or help you can provide, Andrea
the bug is at the concatenateFields() of Point class. as long as the for loop handle a null valued field at the last. the issue appears
I have to say more unit tests needed to ensure the code quality of this project
and a quick fix
final int fieldCount = this.fields.values().stream().filter(Objects::nonNull).collect(Collectors.toList()).size()
If you write a unit-test which shows the problem and a fix as PR i will review it.
Fixed with commit d27c4dbb139f1cd4eddbb5e988e30464eef20703. I'm closing this issue.