Igo*_*nov 6 java google-app-engine google-bigquery google-cloud-platform
基本上我的代码看起来像https://cloud.google.com/bigquery/streaming-data-into-bigquery上的官方示例
我的代码:
TableRow data = new TableRow();
data.set("type", eventType);
data.set("timestamp", new Date());
TableDataInsertAllRequest.Rows row = new TableDataInsertAllRequest.Rows();
row.setInsertId(System.currentTimeMillis());
row.setJson(data);
request = new TableDataInsertAllRequest();
request.setRows(Arrays.asList(row));
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, datasetId, tableId, request).execute();
for (TableDataInsertAllResponse.InsertErrors err: response.getInsertErrors()) {
for (ErrorProto ep: err.getErrors()) {
log.error(ep.getReason() + " : " + ep.getMessage() + " at " + ep.getLocation());
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
invalid : JSON map specified for non-record field at null
Run Code Online (Sandbox Code Playgroud)
似乎我错过了什么,但不知道我的代码有什么问题.我有两个字段,一个String
和Date
,并且错误消息对我没有任何意义.
如何在BigQuery表中插入数据?
Igo*_*nov 19
经过几个小时的调试后,我发现BigQuery Java Client不支持Date
值.而com.google.api.client.util.DateTime
包装应使用.
所以,而不是
data.set("timestamp", new Date());
Run Code Online (Sandbox Code Playgroud)
应该有:
data.set("timestamp", new DateTime(new Date()));
Run Code Online (Sandbox Code Playgroud)
希望它会对某人有所帮助.
归档时间: |
|
查看次数: |
6090 次 |
最近记录: |