Google bigquery 在BiqQuery API中追加而不是覆盖表

Google bigquery 在BiqQuery API中追加而不是覆盖表,google-bigquery,Google Bigquery,我目前使用bigquery.tabledata().insertAll()将数据放入bigquery。但是,它会覆盖所有以前的内容,而不是附加内容。有没有办法改变默认行为,或者我应该使用另一种方法来改变默认行为 代码如下: GoogleCredential credential = GoogleCredential.fromStream(...); if (credential.createScopedRequired()) { credential = credential.crea

我目前使用
bigquery.tabledata().insertAll()
将数据放入bigquery。但是,它会覆盖所有以前的内容,而不是附加内容。有没有办法改变默认行为,或者我应该使用另一种方法来改变默认行为

代码如下:

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();
GoogleCredential-credential=GoogleCredential.fromStream(…);
if(credential.createScopedRequired()){
credential=credential.createScope(BigqueryScopes.all());
}
bigquery=new bigquery.Builder(new NetHttpTransport(),new GsonFactory(),credential).setApplicationName(“bigquery示例”).build();
TableDataInsertAllRequest.Rows r=新的TableDataInsertAllRequest.Rows();
r、 setInsertId(“123”);
ObjectMapper m=新的ObjectMapper();
地图道具=m.convertValue(person,Map.class);
r、 setJson(道具);
TableDataInsertAllRequest内容=
新建TableDataInsertAllRequest().setRows(Arrays.asList(r));
content.setSkipInvalidRows(真);
content.setIgnoreUnknownValues(true);
TableDataInsertAllResponse execute=bigquery.tabledata().insertAll(“,”,“,”,content.execute();
哦,找到了答案。
setInsertId(id)
使用相同(如果设置了)id的插入被具有相同id的next覆盖

解决方案:不要设置InsertId


编辑:请参阅@Mikhail Berlayant response和为什么您应该关心InsertId。

解决方案是将[全局]唯一ID指定为InsertId。
BigQuery使用InsertId属性尽最大努力检测重复的插入请求。
如果您忽略这一点,您可能会得到不需要的重复行
在中查看更多信息