This question is an extension of this question: BigQuery check entire table for null values
I'm very new to BigQuery. I have a large table and would like to avoid ~150 ifnull
calls. However, some of the unnested columns names are the same, and they aren't being handled properly using the answer to the above question. Here's an example of the data fields
itemId
extension.new.name
extension.new.location
extension.old.name
extension.default
extension.category
...
The solution to the linked question is:
#standardSQL
SELECT col_name, COUNT(1) nulls_count
FROM `project.dataset.table` t,
UNNEST(REGEXP_EXTRACT_ALL(TO_JSON_STRING(t), r'"(\w+)":null')) col_name
GROUP BY col_name
and the result I get is somewhat as follows:
col_name nulls_count
name 5
location 8
default 3
category 7
...
But this solution treats both extension.new.name
and extension.old.name
the same due to the group by, but I'd like to have a null count for each individually:
col_name nulls_count
extension.new.name 5
extension.new.location 8
extension.old.name 10
extension.default 3
extension.category 7
Is it possible to get the nested column name with the unnested count? I'm not sure if there is a way to capture the entire name and concatenate them?