2016-11-14 26 views
1

我目前使用bigquery.tabledata().insertAll()将数据放入BigQuery中。但它会覆盖所有以前的内容而不是附加它。有没有更改默认行为的方法,或者我应该使用其他方法来执行此操作吗?下面在BiqQuery API中添加替代表格而不是覆盖表格

代码:

GoogleCredential credential = GoogleCredential.fromStream(...); 

if (credential.createScopedRequired()) { 
    credential = credential.createScoped(BigqueryScopes.all()); 
} 
bigquery = new Bigquery.Builder(new NetHttpTransport(), new GsonFactory(), credential).setApplicationName("Bigquery Samples").build(); 

TableDataInsertAllRequest.Rows r = new TableDataInsertAllRequest.Rows(); 
r.setInsertId("123"); 
ObjectMapper m = new ObjectMapper(); 
Map<String,Object> props = m.convertValue(person, Map.class); 
r.setJson(props); 
TableDataInsertAllRequest content = 
     new TableDataInsertAllRequest().setRows(Arrays.asList(r)); 
content.setSkipInvalidRows(true); 
content.setIgnoreUnknownValues(true); 
TableDataInsertAllResponse execute = bigquery.tabledata().insertAll("", "", "", content).execute(); 

回答

0

哦,找到了答案。 具有相同(如果设置)ID为setInsertId(id)的插入由相同ID的下一个覆盖。

解决方法:不要设置InsertId。

编辑:请参阅@Mikhail Berlayant响应以及为什么您应该关心InsertId。