influxdata / influxdata/influxdb-java
Incorrect long values returned due to json to java conversion
- Langage dominant
- Java
- Étoiles
- 1.2k
- Forks
- 469
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par la reproduction fournie de BatchPoints/Point et le gist associé, puis suivez la conversion du résultat JSON qui transforme le champ long en Double. Déterminez jusqu’à quelle taille les valeurs entières peuvent être conservées sans perte lors d’un aller-retour, et vérifiez que le travail est terminé en confirmant que la valeur reproduite est renvoyée exactement, et non sous la forme d’un Double corrompu.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- database
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100