繁体   English   中英

如何查找和提取 substring BIGQUERY

[英]How to fin and extract substring BIGQUERY

例如,在 BigQuery 表中有一个字符串列:

名称
WW_for_all_feed
EU_param_1_for_all_feed
AU_for_all_full_settings_18+
WW_for_us_param_5_for_us_feed
WW_for_us_param_5_feed
WW_for_all_25+

并且还有一个变量列表,例如:

param_1_for_all
param_5_for_us
param_5 
full_settings

如果“名称”列中的字符串包含此子字符串之一,则需要将其提取:

名称 参数
WW_for_all_feed 没有任何
EU_param_1_for_all_feed param_1_for_all
AU_for_all_full_settings_18+ 完整设置
WW_for_us_param_5_for_us_feed param_5_for_us
WW_for_us_param_5_feed 参数_5
WW_for_all_25+ 没有任何

我想尝试正则表达式并替换,但不知道查找 substring 的模式

在下面使用

select name, param
from your_table
left join params 
on regexp_contains(name, param)    

如果适用于您问题中的示例数据

with your_table as (
  select 'WW_for_all_feed' name union all
  select 'EU_param_1_for_all_feed' union all
  select 'AU_for_all_full_settings_18+' union all
  select 'WW_for_us_param_5_for_us_feed' union all
  select 'WW_for_all_25+' 
), params as (
  select 'param_1_for_all' param union all
  select 'param_5_for_us' union all
  select 'full_settings' 
)    

output 是

在此处输入图像描述

但我有另一个问题(更新的问题)如果其中一个参数是 substring 另一个?

然后在下面使用

select name, string_agg(param order by length(param) desc limit 1) param
from your_table
left join params 
on regexp_contains(name, param)
group by name

如果应用于更新的数据样本 - output 是

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM