Google bigquery 使用insertAll-BigQuery时获取缺少的行
在将数据插入BigQuery时,响应中缺少一行,原因无效 {“错误”:[{“消息”:“缺少行”。,“原因”:“无效”}],“索引”:0},{“错误”:[{“消息”:“缺少行”。,“原因”:“无效”}] 下面是我正在执行的代码: /下面几行调用DFPAPI以获取所有ADUnit AdUnitPage page=inventoryService.GetAdUnitsByState(statementBuilder.toStatement()); List dfpadunits=new ArrayList()Google bigquery 使用insertAll-BigQuery时获取缺少的行,google-bigquery,Google Bigquery,在将数据插入BigQuery时,响应中缺少一行,原因无效 {“错误”:[{“消息”:“缺少行”。,“原因”:“无效”}],“索引”:0},{“错误”:[{“消息”:“缺少行”。,“原因”:“无效”}] 下面是我正在执行的代码: /下面几行调用DFPAPI以获取所有ADUnit AdUnitPage page=inventoryService.GetAdUnitsByState(statementBuilder.toStatement()); List dfpadunits=new ArrayLi
if(page.getResults()!=null){
totalResultSetSize=page.getTotalResultSetSize();
int i=page.getStartIndex();
for(AdUnit AdUnit:page.getResults()){
/*System.out.printf(
找到了%d个ID为“%s”、名称为“%s”的Ad单元。%n“,i++,
adUnit.getId(),adUnit.getName()*/
//Map dfpadunitrow=新HashMap();
//dfpadunitrow.put(adUnit.getId(),adUnit.getName());
Rows-dfpadunit=新的TableDataInsertAllRequest.Rows();
setInsertId(adUnit.getId());
dfpadunit.set(“id”,adUnit.getId());
dfpadunit.set(“name”,adUnit.getName());
添加(dfpadunit);
}
}
TableDataInsertAllRequest内容=新建TableDataInsertAllRequest();
content.setRows(dfpad单位);
content.setSkipInvalidRows(真);
content.setIgnoreUnknownValues(true);
System.out.println(dfpadunits.get(0));
Bigquery.Tabledata.InsertAll请求=bigqueryService.Tabledata().InsertAll(projectId、datasetId、tableId、content);
TableDataInsertAllResponse=request.execute();
System.out.println(response.getInsertErrors());
我让记录器检查我的数据是否正确填充,但当我尝试使用insertAll将记录插入bigquery时,我得到了缺少行的响应,原因无效
谢谢,
Kapil您需要使用一个
TableRow
对象。这个方法有效(我测试过):
您需要使用一个
TableRow
对象。这个方法有效(我测试过):
我的答案对你有用吗?我的答案对你有用吗?
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (AdUnit adUnit : page.getResults()) {
/*System.out.printf(
"%d) Ad unit with ID '%s' and name '%s' was found.%n", i++,
adUnit.getId(), adUnit.getName());*/
//Map<String,Object> dfpadunitrow = new HashMap<String,Object>();
//dfpadunitrow.put(adUnit.getId(), adUnit.getName());
Rows dfpadunit = new TableDataInsertAllRequest.Rows();
dfpadunit.setInsertId(adUnit.getId());
dfpadunit.set("id",adUnit.getId());
dfpadunit.set("name",adUnit.getName());
dfpadunits.add(dfpadunit);
}
}
TableDataInsertAllRequest content = new TableDataInsertAllRequest();
content.setRows(dfpadunits);
content.setSkipInvalidRows(true);
content.setIgnoreUnknownValues(true);
System.out.println(dfpadunits.get(0));
Bigquery.Tabledata.InsertAll request = bigqueryService.tabledata().insertAll(projectId, datasetId, tableId, content);
TableDataInsertAllResponse response = request.execute();
System.out.println(response.getInsertErrors());
TableDataInsertAllRequest.Rows dfpadunit = new TableDataInsertAllRequest.Rows();
TableRow row = new TableRow();
row.set("id",adUnit.getId());
row.set("name",adUnit.getName());
dfpadunit.setInsertId(adUnit.getId());
dfpadunit.setJson(row);
dfpadunits.add(dfpadunit);