I have a very big table in BigQuery formatted as follows:
row | column.key | column.value.string_value | column.value.int_value | column.value.float_value | column.value.boolean_value | id |
---|---|---|---|---|---|---|
1 | key1 | aa | null | null | null | id1 |
key2 | null | null | null | false | ||
key3 | fa | null | null | null | ||
key4 | null | null | null | true | ||
2 | key1 | ab | null | null | null | id1 |
key2 | null | null | null | false | ||
key3 | gf | null | null | null | ||
key4 | null | null | null | false | ||
3 | key1 | af | null | null | null | id2 |
key2 | null | null | null | true | ||
key3 | fa | null | null | null | ||
key4 | null | null | null | false |
I need to re-format it as follows:
row | key1 | key2 | key3 | key4 | id |
---|---|---|---|---|---|
1 | aa | false | fa | true | id1 |
2 | ab | false | gf | false | id1 |
3 | af | true | fa | false | id2 |
I tried to use this but couldn't make it work in my table
How to unnest and pivot two columns in BigQuery
One important thing in my table is that, like in the above table, the ids repeat in different rows but have different values for the same keys. Where the ids repeat I want to still have all incidences of the ids, like in the formatted table example.
Also I put only 4 keys here but I actually have 50, so the least manual it is, the better. If the only way is writing each column manually then I'll still do it though.
Does anyone know how to do it? I basically need to turn every key into a new column with it's corresponding value associated with the ids, but I don't know how to do it.
Thank you very much!