0

I want to use BigQuery Standard SQL

I have a table that looks like:

enter image description here

How would I collapse each row? For or instance, so that row #1 looks something like:

row   Canopus_id    facebook     id      wikipedia    freebase musicbrainz    
1      10043474     21258...    Q557     Patt_Smith     /m/05qw5  d1358...

Essentially we are collapsing the row in such a way that it will try to find a filled entry for a column and if there is a filled entry (either in the first or second cell) that will be the value. Else, there will be a null.

2
  • 1
    is every shown column actually a separate repeated field or it is one repeated record? - would be great to see schema of the table/data Commented Nov 6, 2018 at 22:35
  • @javacash . . . I'm curious what the types of the columns are. Arrays don't support NULL elements. Commented Nov 6, 2018 at 22:55

1 Answer 1

1

Here is one method:

select row,
       (select max(facebook) from unnest(facebook) facebook) as facebook,
       (select max(id) from unnest(id) id) as id,
       . . .
from t;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.