Skip to content
Advertisement

bigquery transpose and concatenate for each record

I want to achieve the following transformation. I have last_name stored in a repeated record as follows.

data before transformation

I want to achieve the following. data after transformation

Example with sample data created.

I’m not sure either if I should store it as an array instead of a concatenated field but it would be good to know how to achieve both. storing the concat_last_name as an array

I have achieved the first transformation as follows but I had to dedup the concatenated field with a function I wrote. I’m sure there is a much better way of achieving this.

The function. string_flatten_dedup

before using function. intermediate results.

Final result after applying dedup function. final output

Updated table structure. t1.ccte1

Yours works but I got the table structure incorrect when I first posted.

Advertisement

Answer

Consider below approach

if applied to sample data in your question data before transformation

output is

enter image description here

In case if you want last names as an array – you already have this array – see below for how to use it

with output

enter image description here

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