Bigquery - How to zip two arrays into one?

Viewed 2241

If I have two arrays in BigQuery that I know are of equal size. How can i zip them into one array of structs or an array of two element arrays or similar?

The following query gives me all possible combinations of x and y which is not what I want.

WITH test AS (
  SELECT
    ['a', 'b', 'c'] as xs,
    [1, 2, 3] as ys
)
SELECT struct(x, y) as pairs 
FROM test, unnest(xs) as x, unnest(ys) as y

I would like to get something like this:

+--------+--------+
| pair.x | pair.y |
+--------+--------+
| a      | 1      |
| b      | 2      |
| c      | 3      |
+--------+--------+
1 Answers
Related