在重复记录中添加新元素时,将空记录保持在BigQuery中
我在BigQuery中有一个类型重复记录的字段,该字段存储了此JSON:
"users": [{
"key": "name",
"value": {
"string_value": foo,
"int_value": null,
"float_value": null,
"double_value": null
}
}, {
"key": "age",
"value": {
"string_value": null,
"int_value": "477",
"float_value": null,
"double_value": null
}
}
我使用Unnest查询这些字段,就像这样:
select * from myTable t,
unnest(users) as name,
unnest(users) as age,
WHERE name.key = 'name'
AND age.key = 'age'
我的问题是我添加了第三个字段,
"users": [{
"key": "name",
"value": {
"string_value": foo,
"int_value": null,
"float_value": null,
"double_value": null
}
}, {
"key": "age",
"value": {
"string_value": null,
"int_value": "477",
"float_value": null,
"double_value": null
}
},
{
"key": "lastName",
"value": {
"string_value": Johnson,
"int_value": null,
"float_value": null,
"double_value": null
}
}
以前不存在姓氏“现在仅包含以前的两个字段的行现在被排除在我的查询之外,甚至使用左联接。
select * from myTable t,
unnest(users) as name,
unnest(users) as age
left join unnest (users) as lastName
WHERE name.key = 'name'
AND age.key = 'age'
AND lastName.key = 'lastName'
这仅返回包含3个字段的行(甚至是左联接),在将新元素添加到重复字段之前,我缺少所有数据。 我如何保持空行?
要澄清,我的查询应该返回这样的东西(现在我没有得到第一个):
John, 12, null
Juan, 14, Perez
I have a field of type repeated record in bigquery that stores this json:
"users": [{
"key": "name",
"value": {
"string_value": foo,
"int_value": null,
"float_value": null,
"double_value": null
}
}, {
"key": "age",
"value": {
"string_value": null,
"int_value": "477",
"float_value": null,
"double_value": null
}
}
I query those field using UNNEST, just like this:
select * from myTable t,
unnest(users) as name,
unnest(users) as age,
WHERE name.key = 'name'
AND age.key = 'age'
My problem is that I have added a third field
"users": [{
"key": "name",
"value": {
"string_value": foo,
"int_value": null,
"float_value": null,
"double_value": null
}
}, {
"key": "age",
"value": {
"string_value": null,
"int_value": "477",
"float_value": null,
"double_value": null
}
},
{
"key": "lastName",
"value": {
"string_value": Johnson,
"int_value": null,
"float_value": null,
"double_value": null
}
}
The last name field didn't exist before so I have "historical" rows that contained only the 2 previous fields that are being excluded from my query now, even using a left join.
select * from myTable t,
unnest(users) as name,
unnest(users) as age
left join unnest (users) as lastName
WHERE name.key = 'name'
AND age.key = 'age'
AND lastName.key = 'lastName'
this ONLY returns rows that contain the 3 fields (even tho is a left join) and I'm missing all the data from before I added the new element to the repeated field.
How can I keep null rows?
To clarify, my query should return something like this (right now I'm not getting the first one):
John, 12, null
Juan, 14, Perez
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您正在查询bq中的firebase数据。
首先,您不应为用户结构中的每个字段添加一个新的加入。
相反,您应该在数组中搜索键,然后在Value struct中获取相关字段。
上面,我为名称和姓氏使用字符串值,以及年龄字段的int值。请调整这些数据。
I guess you're querying Firebase data in BQ.
Firstly, you shouldn't add a new join for each field in user struct.
Instead, you should search for the key in the array and then get the relevant field in value struct.
Above, I used string value for name and lastname, and int value for age fields. Please adjust these for your data.