【发布时间】:2018-02-09 12:08:18
【问题描述】:
我是 bigquery 的新手,所以我不完全了解如何将数据流式传输到 bigquery,这是我的问题,我有 jsonInString,从这样的对象映射
String customerJsonInString = mapper.writeValueAsString(customer);
{
"id": "1",
"first_name": "John",
"last_name": "Doe",
"dob": "1968-01-22",
"addresses": [
{
"status": "current",
"address": "123 First Avenue",
"city": "Seattle",
"state": "WA",
"zip": "11111",
"numberOfYears": "1"
},
{
"status": "previous",
"address": "456 Main Street",
"city": "Portland",
"state": "OR",
"zip": "22222",
"numberOfYears": "5"
}
]
}
已使用正确的架构创建表。 现在我想将此数据流式传输到 bigquery(插入行),我正在使用 (https://cloud.google.com/bigquery/streaming-data-into-bigquery#bigquery-stream-data-java) 上的示例来适应我的,这就是我尝试过的,
TableId tableId = TableId.of(DATASET_NAME,TABLE_NAME);
Map<String, Object> recordsContent = new HashMap<>();
recordsContent.put("Customer", customerJsonInString);
InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId)
.addRow("rowId", recordsContent)
.build());
if (response.hasErrors()) {
for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
}
}
【问题讨论】:
-
我猜表的架构是“id, first_name, last_name, ...”而不是“customer”?在这种情况下,您需要一个一个地设置字段而不是整个 json 字符串,例如"recordsContent.put("id", 1)".
-
@HuaZhang 您能否将您的解决方案添加为正确的 SO 答案?社区将受益于答案所具有的各种功能,您将从名声中受益:) 谢谢!
标签: java json google-bigquery