我正在尝试使用JAVA API流式传输重复的记录字段。它插入记录但具有空值。我使用的数据和架构来自Google的#34;嵌套和重复数据"
的示例以下是代码段:
TableRow row = new TableRow();
row.set("kind", "person");
row.set("fullName", "P");
row.set("age", "22");
row.set("gender", "M");
TableRow prow = new TableRow();
prow.set("areaCode", 206);
prow.set("number", 1234567);
row.set("phoneNumber", prow);
JsonArray children = new JsonArray();
JsonObject child1 = new JsonObject();
child1.addProperty("name", "Jane");
child1.addProperty("gender", "f");
child1.addProperty("age", 6);
children.add(child1);
JsonObject child2 = new JsonObject();
child2.addProperty("name", "John");
child2.addProperty("gender", "m");
child2.addProperty("age", 15);
children.add(child2);
row.set("children", children);
TableDataInsertAllRequest.Rows rows = new TableDataInsertAllRequest.Rows();
rows.setJson(row);
List rowList = new ArrayList();
rowList.add(rows);
TableDataInsertAllRequest content = new TableDataInsertAllRequest().setRows(rowList);
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, "tmp", "person5", content).execute();
答案 0 :(得分:2)
而不是JsonArray创建List工作如下:
List<TableRow> children = new ArrayList<TableRow>();
TableRow child1 = new TableRow();
child1.set("name", "Jane");
child1.set("gender", "f");
child1.set("age", 6);
TableRow child2 = new TableRow();
child2.set("name", "John");
child2.set("gender", "m");
child2.set("age", 15);
children.add(child1);
children.add(child2);