[英]How to find the value "-32767" in 450 columns in a BigQuery table?
I have a BigQuery table with 450 columns and millions of rows.我有一个包含 450 列和数百万行的 BigQuery 表。 As can be expected, the table has columns of all types like datetime, date, integer, numeric and string.正如所料,该表包含所有类型的列,例如日期时间、日期、integer、数字和字符串。 I want to know which column contains the value "-32767".我想知道哪一列包含值“-32767”。 Is there a way to accomplish this in BigQuery ?有没有办法在BigQuery中完成此操作?
Consider below考虑以下
create temp function extract_keys(input string) returns array<string> language js as """
return Object.keys(JSON.parse(input));
""";
create temp function extract_values(input string) returns array<string> language js as """
return Object.values(JSON.parse(input));
""";
select col, count(*) cnt
from your_table t,
unnest([struct(to_json_string(t) as json)]),
unnest(extract_keys(json)) col with offset
join unnest(extract_values(json)) val with offset
using(offset)
where val = '-32767'
group by col
this will give you output like below这会给你 output 如下
Where col3, col2 are columns that have -32767
value and 4,1 is how many rows involved respectively其中 col3、col2 是具有-32767
值的列,4,1 分别是涉及的行数
How can I modify it and give it a subset of columns where I expect the value can be?我如何修改它并为其提供我期望值的列的子集?
Assuming you want to limit "search" to only col1
and col3
- use below假设您想将“搜索”限制为仅col1
和col3
- 请在下面使用
select col, count(*) cnt
from your_table t,
unnest([struct(to_json_string((select as struct col1, col3 from unnest([t]))) as json)]),
unnest(extract_keys(json)) col with offset
join unnest(extract_values(json)) val with offset
using(offset)
where val = '-32767'
group by col
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.