Skip to content
Advertisement

Add nested column to BigQuery table, joining on value of another nested column in standard SQL

I have a reasonably complex dataset being pulled into BigQuery table via an Airflow DAG which cannot easily be adjusted.

This job pulls data into a table with this format:

At the moment, I am using this query (written in standard SQL within the BQ Web UI) to split the device ids into individual nested rows:

Output:

The difficulty I am facing is I have a separate match table containing the device ids and their corresponding names. I need to add the device names to the above table, as nested values next to their corresponding ids.

The match table looks something like this (with many more rows):

The ideal output I am looking for would be:

If anybody knows how to achieve this I would be grateful for help.

EDIT:

Gordon’s solution works perfectly, but in addition to this, if anybody wants to re-nest the data afterwards (so you effectively end up with the same table and additional nested rows), this was the query I finally ended up with:

Advertisement

Answer

You can move the parsing logic to the from clause and then join in what you want:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement