我在 Cloud BigQuery 中有一个表,但service.Tabledata.InsertAll调用确实将数据插入到嵌套字段中。// works jsonRow["name"] = bigquery.JsonValue("Name")// doesn't workjsonRow["geo_location.City.Names.en"] = bigquery.JsonValue("Irvine")rows[index] = new(bigquery.TableDataInsertAllRequestRows)rows[index].Json = jsonRowinsertRequest := &bigquery.TableDataInsertAllRequest{Rows: rows}insertRequest.IgnoreUnknownValues = truecall := service.Tabledata.InsertAll(project, dataset, "analytics_events", insertRequest)if res, err := call.Do(); err!=nil{ Log.Fatal("Unable to Insert to BigQuery ", err) return err}
2 回答
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
您实际上需要构建一个与架构结构相匹配的对象结构。
这里的困惑在于该行:
jsonRow["geo_location.City.Names.en"] = bigquery.JsonValue("Irvine")
不会创建您期望的对象结构。您创建的 json 对象实际上如下所示:
{
"geo_location.City.Names.en": "Irvine"
}
而你想要的东西看起来像:
{
"geo_location": {
"City": {
"Names": {
"en": "Irvine"
}
}
}
}
所以你的代码应该是这样的:
// Probably not valid code. Just guessing.
jsonRow["geo_location"] = bigquery.JsonObject()
jsonRow["geo_location"]["City"] = bigquery.JsonObject()
jsonRow["geo_location"]["City"]["Names"] = bigquery.JsonObject()
jsonRow["geo_location"]["City"]["Names"]["en"] = bigquery.JsonValue("Irvine")
希望有帮助。
- 2 回答
- 0 关注
- 155 浏览
添加回答
举报
0/150
提交
取消