googleapis / googleapis/google-http-java-client

Not allowing Infinite values for Double

未关闭
#1,769 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
type: feature request
主要语言
Java
星标
1.4k
派生
473
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。