influxdata / influxdata/influxdb-java
Incorrect long values returned due to json to java conversion
- Lingua principale
- Java
- Stelle
- 1.2k
- Fork
- 469
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I am having a problem with bad long values being returned due to the conversion to double that happens when all JSON numeric values are stored as Doubles.
This came up first when trying to get back time values as nanoseconds instead of rfc3339 string values. But we need to store very large long values in other fields as well. The application here is scientific instruments, so numerical errors are pretty high priority problems when we are looking at data storage.
From looking around, it does not look like there is a good way to intercept the JSON and convert to Long instead of Double... but maybe I am missing something? I would like to find some way to get these values returned as Long instead of Double. Maybe a different converter? I would appreciate any suggestions or workarounds.
Here is a snippet that recreates the problem:
```
long lval = 1485370052974000001L;
BatchPoints batchPoints = BatchPoints
.database(dbName)
.tag("async", "true")
.retentionPolicy("autogen")
.consistency(ConsistencyLevel.ALL)
.build();
Point point = Point.measurement("testProblems")
.time(innano, TimeUnit.NANOSECONDS)
.addField("double", 3.14)
.addField("long", lval)
.build();
batchPoints.point(point);
influxDB.write(batchPoints);
Series series0 = result.getResults().get(0).getSeries().get(0);
List cols = series0.getColumns();
List val0 = series0.getValues().get(0);
Object outlval_obj = val0.get(cols.indexOf("long"));
if (outlval_obj instanceof Double)
{
long outlval = ((Double)outlval_obj).longValue();
if (outlval != lval)
{
System.err.println("Got bad lval back as double [" + (outlval_obj) + "] -> " + outlval + " != " + lval);
}
}
```
Here is a gist with more code and outputs:
https://gist.github.com/ghmegan/4ed652c8c8dbaf18976c6f5f4c0c6b55
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia con la riproduzione fornita di BatchPoints/Point e con il gist collegato, quindi segui la conversione del risultato JSON che trasforma il campo long in un Double. Determina quali valori interi grandi possono essere sottoposti a round-trip senza perdita e verifica il completamento confermando che il valore riprodotto venga restituito esattamente, anziché come un Double corrotto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- database
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100