[英]bigquery: query data JSON
I have an JSON objet withs ID / keys.我有一个带有 ID/密钥的 JSON 对象。
Within those keys is the result of each analysis of each ID.在这些键中是每个 ID 的每次分析的结果。
"raw_result":{"3117092402546":true,"3110924118082":false,"3117014230082":true,"3171295576130":true}
I need to extract that information in some way that allows me to make queries later.我需要以某种方式提取该信息,以便稍后进行查询。 For example: an array of data.
例如:一组数据。
result I expected我期望的结果
**document_id id result**
918348 3117092402546 true
918348 3110924118082 false
918348 3117014230082 true
918348 3171295576130 true
could you help me?你可以帮帮我吗?
Try this one:试试这个:
WITH sample AS (
SELECT JSON_QUERY('{"raw_result":{"3117092402546":true,"3110924118082":false,"3117014230082":"true","3171295576130":true}}', '$.raw_result') json
)
SELECT k AS id, v AS result
FROM sample,
UNNEST(bqutil.fn.json_extract_keys(json)) k WITH OFFSET ki,
UNNEST(bqutil.fn.json_extract_values(json)) v WITH OFFSET vi
WHERE ki = vi
;
And for the UDFs I've used, you can check them on below site:对于我使用的 UDF,您可以在以下站点上查看它们:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.