Regexp在Bigquery中将键值拆分为列
我的列数据看起来像 “dayparts”:[{“day”:“Saturday”,“hours”:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],{“day”:“Sunday”,“hours”:[0,1,2,3,4,5,6,8,9,10,11,12,13],{“day”:“星期四”,“hours”:[0,1,2,3,4,5,6,7,8,9,10,12,13]}] 我希望有这样的结果 您可以尝试:Regexp在Bigquery中将键值拆分为列,regex,dictionary,google-bigquery,Regex,Dictionary,Google Bigquery,我的列数据看起来像 “dayparts”:[{“day”:“Saturday”,“hours”:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],{“day”:“Sunday”,“hours”:[0,1,2,3,4,5,6,8,9,10,11,12,13],{“day”:“星期四”,“hours”:[0,1,2,3,4,5,6,7,8,9,10,12,13]}] 我希望有这样的结果 您可以尝试: WITH sample AS ( SELECT "1" AS
WITH sample AS (
SELECT "1" AS id, "{\"dayparts\":[{\"day\":\"Saturday\",\"hours\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]},{\"day\":\"Sunday\",\"hours\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]},{\"day\":\"Thursday\",\"hours\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]}]}" AS msg
)
SELECT id,
JSON_VALUE(dparts, '$.day') AS day,
JSON_QUERY(dparts, '$.hours') AS hours
FROM (
SELECT id,
JSON_EXTRACT_ARRAY(JSON_QUERY(msg, '$.dayparts')) AS dayparts
FROM sample) t, UNNEST(t.dayparts) dparts
(我添加了封闭的“{”和“}”,以便能够执行JSON操作,如果它们不在那里,我想只是将它们串联起来)
(如果希望在结果表中使用实际数组,还可以在“JSON_查询(dparts,$.hours')”周围添加“JSON_提取_数组”)