BigQuery check entire table for null values

大憨熊 提交于 2021-01-07 06:11:20

问题


Not sure if a reproducible example is necessary here. I have a big-ish and wide-ish table in BigQuery (10K rows x 100 cols) and I would like to know if any columns have null values, and how many null values there are. Is there a query that I can run that would return a 1-row table indicating the number of null values in each column, that doesn't require 100 ifnull calls?

Thanks!


回答1:


Below is for BigQuery Standard SQL

#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 

Instead of returning just one row - it returns those column which have NULL in them - each column and count in separate row - like in below example

Row col_name    nulls_count  
1   col_a       21   
2   col_d       12   


来源:https://stackoverflow.com/questions/58716640/bigquery-check-entire-table-for-null-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!