[英]Filter elements from array in bigquery
我有一個具有以下結構的 bigquery 表:
select ["apple", "of", "the", "tree"] as array_col, 1 as label
union all (select ["boy", "of", "the", "streets"] as array_col, 2 as label);
我想通過查詢獲得 arrays 中沒有某些元素的表。 例如,我想過濾array_col
數組的元素of
或the
得到下表:
select ["apple", "tree"] as array_col, 1 as label
union all (select ["boy", "streets"] as array_col, 2 as label);
有沒有一種簡單的方法可以在 biquery 中做到這一點?
謝謝!
從文檔:
with arrays as (
select ["apple", "of", "the", "tree"] as array_col, 1 as label
union all (select ["boy", "of", "the", "streets"] as array_col, 2 as label)
)
select
array(
select x
from unnest(array_col) AS x
where x not in ('of', 'the')
) as array_filter,
label
from arrays;
您可以使用REGEXP
過濾它。 它可能有助於過濾多個數組列或大表
WITH arrays as (
SELECT ["apple", "of", "the", "tree"] array_col, 1 label
UNION ALL (SELECT ["boy", "of", "the", "streets"] array_col, 2 label)
)
SELECT JSON_VALUE_ARRAY(REGEXP_REPLACE(TO_JSON_STRING(array_col), r'("of",)|("the",)',''), '$') array_col, label
FROM arrays
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.