Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Bigquery remove the nested columns which has "REPEATED" mode

Using Bigquery I was trying to remove nested schema like below, but couldn’t able to do so. Can anyone please let me know. How to achieve that?

Table:

FiledName          Type       Mode
Person            RECORD   REPEATED
Person.Name       STRING   NULLABLE
Person.Add        RECORD   NULLABLE
Person.Add.line   STRING   NULLABLE

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

create table `project_id.dataset.new_table_name` as 
select * replace(
   (select as ARRAY(struct person.* except(add))) as person
)
from `project_id.dataset.table_name`;

Expected Output:

FiledName          Type       Mode
Person            RECORD   REPEATED
Person.Name       STRING   NULLABLE

>Solution :

Consider below approach

create table `project_id.dataset.new_table_name` as 
select * replace(
    array(select as struct person.* except(add) from t.person) as person
  )
from `project_id.dataset.table_name` t;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading