Skip to content
Advertisement

Flatten the Data in BigQuery

I have dimensions.key_value of RECORD type i run the following query with following output.

To unnest the data i have created the following view:

My Output:

There are two thing i need to verify is my query correct ? How i can make the query generic i.e if i don’t know all the key, there some other keys may also be present in our dataset ?

Update:

My Schema : enter image description here

My OutPut : enter image description here

Problem : Let says a user want to do group by using region and loc so there is no easy way of writing the query for that i decided create a view so user can easily do group by

Based on this view the user can easily do group by. So i wanted to check if their is way to create generic view since we don’t know the all the unique key or is there a easy way to do groupby.

Advertisement

Answer

How i can make the query generic i.e if i don’t know all the key, there some other keys may also be present in our dataset ?

Consider below

if applied to sample data in your question – ooutput is

enter image description here

As you can see in query – there is no any explicit references to actual key names – rather they are dynamically extracted – so no need to know them in advance and there can be any number of them too

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