googleapis / googleapis/google-http-java-client
Not allowing Infinite values for Double
- Vorherrschende Sprache
- Java
- Sterne
- 1.4k
- Forks
- 473
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Problem you have encountered:
```
Error sending insert request, table: xxxx
com.google.cloud.bigquery.BigQueryException: java.lang.IllegalArgumentException
at com.google.cloud.bigquery.BigQueryException.translateAndThrow(BigQueryException.java:100)
at com.google.cloud.bigquery.BigQueryImpl.insertAll(BigQueryImpl.java:979)
...
Caused by: java.lang.IllegalArgumentException
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:35)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:134)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:173)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:173)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:173)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:146)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:173)
at com.google.api.client.json.JsonGenerator.serialize(JsonGenerator.java:105)
```
It seems that the json serializer is very restrictive (not able to change/configure it) in handling Infinity values, which are actually supported by BigQuery and Double standard.
https://github.com/googleapis/google-http-java-client/blob/main/google-http-client/src/main/java/com/google/api/client/json/JsonGenerator.java#L134
What you expected to happen:
I would expect the JsonGenerator, to be able to pass Infinity (as a string?) and not hard fail.
e.g. draft
```
double doubleValue = ((Number) value).doubleValue();
if (Double.isInfinite(doubleValue)){ // or if (Double.isInfinite(doubleValue && allowDoubleInfinityAsString))
writeString("infinity");
} else {
Preconditions.checkArgument(!Double.isInfinite(doubleValue) && !Double.isNaN(doubleValue));
writeNumber(doubleValue);
}
```
The alternative of cleaning the data with Infinity values before inserting it would imply loss of information due to the transportation mechanism, which shouldn't be a limitation itself
Beitragsleitfaden
Rechercherichtung
Start at google-http-client/src/main/java/com/google/api/client/json/JsonGenerator.java around line 134, where the serializer rejects non-finite doubles. Review the surrounding numeric serialization behavior and determine how Infinity should be represented or configured. Done means the serializer no longer fails for the requested Infinity case while preserving existing validation behavior for unsupported values.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100