如何从 bigquery 中数据类型为字符串的字典列中查询位置?

How to query where from dictionary column with datatype string in bigquery?

您好,我有一列包含数据类型为字符串的字典。如何在 bigquery sql 中查询 where attributes.statusSource = source? 这是一个例子

id attributes
1 {"flushOut": 0, "expiration": 0, "productAge": 0, "sourceStatus": "SOURCE", "criticalStatus": false, "storageHandling": "FROZEN", "expirationReminder": 0}
2 {"flushOut": 0, "expiration": 0, "productAge": 0, "sourceStatus": "DISCONTINUE", "criticalStatus": false, "storageHandling": "FROZEN", "expirationReminder": 0}

我想要返回的是 attribute.sourceStatus = "source"

id attributes
1 {"flushOut": 0, "expiration": 0, "productAge": 0, "sourceStatus": "SOURCE", "criticalStatus": false, "storageHandling": "FROZEN", "expirationReminder": 0}

使用JSON_EXTRACT_SCALAR()

SELECT * FROM (
SELECT '{"flushOut": 0, "expiration": 0, "productAge": 0, "sourceStatus": "SOURCE", "criticalStatus": false, "storageHandling": "FROZEN", "expirationReminder": 0}' as attributes
UNION ALL
SELECT '{"flushOut": 0, "expiration": 0, "productAge": 0, "sourceStatus": "DISCONTINUE", "criticalStatus": false, "storageHandling": "FROZEN", "expirationReminder": 0}' as attributes
) WHERE JSON_EXTRACT_SCALAR(attributes, '$.sourceStatus') = 'SOURCE'