如何用java将nan写入biqquery?

5cg8jx4n  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(332)

在biqquery表中,我们可以使用 isNaN() 检查nan值。
但是如何用java(jvm语言)将nan写入bigquery表呢?
写字符串“nan”?
欢迎任何评论。谢谢

更新

我们想把 Double.NaN ,但大查询不接受它并引发异常。不知道为什么。

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)
nuypyhwy

nuypyhwy1#

下面是bigquery标准sql,并给出了几种生成nan的方法,我只是用is_nan Package 它,以检查结果实际上是nan,而不仅仅是字符串'nan'

SELECT
  test1,
  IS_NAN(test1),
  test2,
  IS_NAN(test2)
FROM (  
SELECT 
  IEEE_DIVIDE(0, 0) test1, 
  CAST('NaN' AS FLOAT64) test2
)

有结果的

Row test1   f0_     test2   f1_  
1   NaN     true    NaN     true

相关问题