SP_6721
Honored Contributor II

Hi @AdamIH123 ,

The explode-based approach is widely used and remains the most reliable and readable method.

But if you're looking for an alternative without using explode, you can try the REDUCE + MAP_FILTER approach. It lets you aggregate maps across rows efficiently:

SELECT
  id,
  MAP_FILTER(
    REDUCE(
      COLLECT_LIST(color_map),
      MAP('init', 0),
      (acc, m) -> MAP_ZIP_WITH(
        acc,
        m,
        (k, v1, v2) -> COALESCE(v1, 0) + COALESCE(v2, 0)
      )
    ),
    (k, v) -> k != 'init'
  ) AS aggregated_color_map
FROM cte
GROUP BY id;

View solution in original post