Basically my code looks like official example at https://cloud.google.com/bigquery/streaming-data-into-bigquery
My code:
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());
}
}
But I getting error:
invalid : JSON map specified for non-record field at null
Seems that I've missed something, but have no idea what's wrong with my code. I have two fields, a String
and Date
, and error message doesn't make any sense to me.
How to insert data in BigQuery table?
After few hours of debugging I found that BigQuery Java Client doesn't support Date
values. And com.google.api.client.util.DateTime
wrapper should be used.
So, instead of
data.set("timestamp", new Date());
there should be:
data.set("timestamp", new DateTime(new Date()));
Hope it will help somebody.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With