使用insertAll - BigQuery时丢失行

时间:2016-05-03 11:00:15

标签: google-bigquery

在将数据插入BigQuery时,我发现缺少有无效理由的行。

{“errors”:[{“message”:“Missing row。”,“reason”:“invalid”}],“index”:0},{“errors”:[{“message”:“Missing行 “” 理由。 “:” 无效“}]

以下是我正在执行的代码:

/以下行调用dfp API来获取所有adunits AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());                     列出dfpadunits = new ArrayList();

                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());

我把记录器检查我的数据是否正确填充但是当我尝试使用insertAll将记录插入bigquery时,我会因为无效原因而错过了行。

谢谢, 卡皮尔

1 个答案:

答案 0 :(得分:4)

您需要使用TableRow对象。这有效(我测试过):

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);