datetime - 通过 BigQuery 库发送的时间戳对象返回错误“此字段不是记录”
问题描述
将日期字段作为对象发送到类型为时间戳的 BigQuery 表时,google java API 库不会引发异常,但不会引发数据。检查“InsertAllResponse”响应类型返回包括错误“此字段不是记录”。
例如
Hashmap<String,Object> rowContent = new Hashmap<>();
rowContent.put("Time", new Date());
rowContent.put("Name", "Harry");
接着
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());
返回一个 response.hasErrors() true。
还报告了此处的python 和此处的firebase 以及此处的javascript
解决方案
似乎将日期作为对象发送会导致客户端 API 创建 JSON 记录而不是单个字段(这也表明日期时间类型尚未明确映射,因此可能会引入时区问题)。
相反,将日期/时间发送为自 1970 年以来的 UTC秒数,即修改上述内容:
Hashmap<String,Object> rowContent = new Hashmap<>();
rowContent.put("Time", Math.floor(new Date().getTime()/1000));
rowContent.put("Name", "Harry");
(注意:不知道如何处理毫秒,例如BigQuery not handling timestamp in millisecond with partition column,我会找出并回来)
推荐阅读
- unix - 在 MAC OS X 上从 UNIX 终端运行 Google Chrome 的 Shell 代码
- ios - IphoneX 屏幕未覆盖科尔多瓦项目中的页眉和页脚
- mysql - 不嵌套重写 SQL 查询
- botframework - Microsoft Teams 消息扩展不显示搜索的多个参数列表
- .net - 将 .net core 2.2 控制台应用程序升级到 .net core 3.0。3.0 不可用
- ios - 如何在 UITableView 中选择一行?
- simulink - 将初始条件添加到自定义 Simulink 离散时间积分器模块
- nlp - 如何解释对齐工具 fast_align 中的对齐分数?
- javascript - 如何使用带有 api 密钥的 axios get/post 请求?
- world-of-warcraft - 艾泽拉斯核:未创建游戏对象(GUID: , Entry: )。建议的坐标无效