[英]Bigquery Select from table where any column contains 'FINISHED'
I have table in bigquery which has over 100 columns and has more than 70 Million row. 我在bigquery中有一个表,它有100多个列,行数超过7000万。 I want to find out if I can write a query to extract rows where any of the column contains a value 'FINISHED'. 我想知道我是否可以编写一个查询来提取任何列包含值'FINISHED'的行。
Below is for BigQuery Standard SQL Should be good start for you :) 下面是BigQuery标准SQL应该是你的好开始:)
#standardSQL
SELECT <columns to output>
FROM yourTable AS t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), 'finished')
You can test/play with it with below dummy data 您可以使用以下虚拟数据测试/播放它
#standardSQL
WITH yourTable AS (
SELECT 'a' AS x, 'b' AS y, 'c' AS z UNION ALL
SELECT 'finished', '', '' UNION ALL
SELECT '', 'Bigquery Select from table where any column contains "FINISHED"','' UNION ALL
SELECT '', '', 'aaa' UNION ALL
SELECT 'finished', 'bbb', 'finished'
)
SELECT *
FROM yourTable AS t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), 'finished')
Update 更新
Note: if you have your search word as a part of at least one column name - above will return all rows! 注意:如果您将搜索词作为至少一个列名的一部分 - 上面将返回所有行! To address this - you would need to invest a little bit more coding 要解决这个问题 - 你需要投入更多的代码
For example, for simple schema (with no record or repeated) this would be a 例如,对于简单的模式(没有记录或重复),这将是一个
#standardSQL
SELECT <columns to output>
FROM yourTable AS t
WHERE (SELECT COUNTIF(SPLIT(zzz, ':')[SAFE_OFFSET(1)] LIKE '%finished%')
FROM UNNEST(SPLIT(SUBSTR(LOWER(TO_JSON_STRING(t)),2,LENGTH(TO_JSON_STRING(t))-2))) AS zzz
) > 0
You can test this with below 您可以使用下面的测试
#standardSQL
WITH yourTable AS (
SELECT 'a' AS x, 'b' AS y, 'c' AS col_finished UNION ALL
SELECT 'finished', '', '' UNION ALL
SELECT '', 'Bigquery Select from table where any column contains "FINISHED"','' UNION ALL
SELECT '', '', 'aaa' UNION ALL
SELECT 'finished', 'bbb', 'finished'
)
SELECT *
FROM yourTable AS t
WHERE (SELECT COUNTIF(SPLIT(zzz, ':')[SAFE_OFFSET(1)] LIKE '%finished%')
FROM UNNEST(SPLIT(SUBSTR(LOWER(TO_JSON_STRING(t)),2,LENGTH(TO_JSON_STRING(t))-2))) AS zzz
) > 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.