You have one struct that is repeated. So, I think you want:
SELECT origin,
s.destination,
s.visitors
FROM dataset.table t CROSS JOIN
UNNEST(t.struct) s;
EDIT:
I see, you have a struct of two arrays. You can do:
SELECT origin, d.destination, v.visitors
FROM dataset.table t CROSS JOIN
UNNEST(struct.destination) s WITH OFFSET nd LEFT JOIN
UNNEST(struct.visitors) v WITH OFFSET nv
ON nd = nv
Answer from Gordon Linoff on Stack OverflowYou have one struct that is repeated. So, I think you want:
SELECT origin,
s.destination,
s.visitors
FROM dataset.table t CROSS JOIN
UNNEST(t.struct) s;
EDIT:
I see, you have a struct of two arrays. You can do:
SELECT origin, d.destination, v.visitors
FROM dataset.table t CROSS JOIN
UNNEST(struct.destination) s WITH OFFSET nd LEFT JOIN
UNNEST(struct.visitors) v WITH OFFSET nv
ON nd = nv
Difficult to test by not having the underlying data to test on, so I created my own query with your dataset. As far as I can tell destination|visitors is not in an ARRAY-format, but rather in a STRUCT-format, so you do not need UNNEST it. Also view this thread please :)
SELECT
origin,
COUNT(struct.destination),
COUNT(struct.visitors)
FROM dataset.table
GROUP BY 1
Hi,
I just started a new internship and wanted to learn how to use STRUCT, ARRAY and UNNEST.
I have some Python knowledge and I understand that ARRAY is something like a Python list, but I just can't wrap my head around STRUCT. I don't really understand the concept and the materials I find on the internet are just not speaking to me.
Does anyone have some resources that helped you understand how to work with STRUCT, ARRAY and UNNEST?
sql - How can I unnest a string of an array of structs in bigquery? - Stack Overflow
Unnest an Array
Resources for learning STRUCT, ARRAY, UNNEST
Structs in Big Query
Videos
Consider below approach
select table_catalog, table_schema, table_name,
array(
select as struct arr[offset(0)] key, arr[offset(1)] value
from unnest(regexp_extract_all(option_value, r'STRUCT\(("[^"]+", "[^"]+")\)')) kv,
unnest([struct(split(replace(kv, '"', ''), ', ') as arr)])
) options
from sample_dataset.INFORMATION_SCHEMA.TABLE_OPTIONS
where table_name = 'sample_data'
and option_name = 'labels'
if applied to sample use case in your question - output is

Another option to the nice solution offered by @Mikhail_Berlyant would be to use the TO_JSON function when it will be available.
Since January 2022, JSON is now a data type supported by BigQuery, but is not yet Generally Available.
When it becomes GA (or if you are lucky enough to already have access, I think it's possible to apply) you can simply do:
SELECT * EXCEPT (option_value),
TO_JSON(option_value) AS option_value_json
FROM sample_table.INFORMATION_SCHEMA.TABLE_OPTIONS
And you will be able to extract the information you need very simply with the BQ JSON function.
Some refs: here and here