Mar*_*ima 3 datetime google-bigquery
当将日期字段作为对象发送到类型为时间戳的 BigQuery 表时,Google Java API 库不会引发异常,但不会出现数据着陆。检查“InsertAllResponse”响应类型返回包括错误“此字段不是记录”。
例如
Hashmap<String,Object> rowContent = new Hashmap<>();
rowContent.put("Time", new Date());
rowContent.put("Name", "Harry");
Run Code Online (Sandbox Code Playgroud)
进而
BigQuery bq = BigQueryOptions.getDefaultInstance().getService();
TableId tableId = TableId.of(datasetName, tableName);
InsertAllRequest.Builder insertReqBuilder = InsertAllRequest.newBuilder(tableId);
insertReqBuilder.addRow({some string}, row);
InsertAllResponse response = bigquery.insertAll(insertReqBuilder.build());
Run Code Online (Sandbox Code Playgroud)
返回一个response.hasErrors() true。
看来,将日期作为对象发送会导致客户端 API 创建 JSON 记录而不是单个字段(这还表明日期时间类型尚未显式映射,因此可能会引入时区问题)。
相反,以 1970 年以来的 UTC秒数发送日期/时间,即修改上述内容:
Hashmap<String,Object> rowContent = new Hashmap<>();
rowContent.put("Time", Math.floor(new Date().getTime()/1000));
rowContent.put("Name", "Harry");
Run Code Online (Sandbox Code Playgroud)
(注意:不确定如何处理毫秒,请参见例如BigQuery not deal with timestamp in millisecond with partition columns,我会找出并返回)
| 归档时间: |
|
| 查看次数: |
3899 次 |
| 最近记录: |