I want to group by on an array.
sample query:
#standardSQL
WITH `project.dataset.table` AS (
SELECT \'compute\' description, \'[{\"key\":\"application
#standardSQL
WITH `project.dataset.table` AS (
SELECT 'compute' description, '[{"key":"application","value":"scaled-server"},{"key":"department","value":"hrd"}]' labels, 0.323316 cost UNION ALL
SELECT 'compute' description, '[{"key":"application","value":"scaled-server"},{"key":"department","value":"hrd"}]' labels, 0.342825 cost
), temp AS (
SELECT description, labels, SUM(cost) AS cost
FROM `project.dataset.table`
GROUP BY description, labels
)
SELECT
description,
ARRAY(
SELECT AS STRUCT
JSON_EXTRACT_SCALAR(kv, '$.key') key,
JSON_EXTRACT_SCALAR(kv, '$.value') value
FROM UNNEST(SPLIT(labels, '},{')) kv_temp,
UNNEST([CONCAT('{', REGEXP_REPLACE(kv_temp, r'^\[{|}]$', ''), '}')]) kv
) labels,
cost
FROM temp