gpt4 book ai didi

google-bigquery - 重复记录 - 嵌套和重复数据 - Java API

转载 作者:行者123 更新时间:2023-12-02 01:49:29 25 4
gpt4 key购买 nike

我正在尝试使用 JAVA API 流式传输重复记录字段。它插入记录但具有空值。我使用的数据和模式来自谷歌的“嵌套和重复数据”示例

以下是代码片段:

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

最佳答案

创建 List 而不是 JsonArray 的工作方式如下:

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

关于google-bigquery - 重复记录 - 嵌套和重复数据 - Java API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23706374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com