regex - 如何为共享相同根的项目列表编写正则表达式
问题描述
所以我有一个关键字列表:
['xxxxl','xxxl','xxl','xl','xxxxt','xxxt','xxt','xt']
在 bigquery 中,我想在下面的 sql 代码中编写一个正则表达式
SELECT my_column
FROM table
REGEXP_CONTAINS(lower(my_column),regex)
这样我的输出表只包含与关键字列表中的任何项目都不匹配的值。
谢谢
解决方案
以下是 BigQuery 标准 SQL
#standardSQL
WITH `project.dataset.lookup_table` AS (
SELECT ['xxxxl','xxxl','xxl','xl','xxxxt','xxxt','xxt','xt'] keywords
)
SELECT my_column
FROM `project.dataset.table`,
(SELECT STRING_AGG(LOWER(keyword), '|') exclude_pattern
FROM `project.dataset.lookup_table`,
UNNEST(keywords) keyword)
WHERE NOT REGEXP_CONTAINS(LOWER(my_column), exclude_pattern)
您可以使用下面的简化示例测试/玩上面
#standardSQL
WITH `project.dataset.lookup_table` AS (
SELECT ['xxxxl','xxxl','xxl','xl','xxxxt','xxxt','xxt','xt'] keywords
), `project.dataset.table` AS (
SELECT 'xxxxl' my_column UNION ALL
SELECT 'abc'
)
SELECT my_column
FROM `project.dataset.table`,
(SELECT STRING_AGG(LOWER(keyword), '|') exclude_pattern
FROM `project.dataset.lookup_table`,
UNNEST(keywords) keyword)
WHERE NOT REGEXP_CONTAINS(LOWER(my_column), exclude_pattern)
带输出
Row my_column
1 abc
推荐阅读
- python - 如何从更深目录中的文件导入模块?
- wordpress - 图像未填充宽度屏幕
- javascript - 如何替换 iframe 标记内的子字符串
- c# - 执行私有方法时无法切换到 Unicode 错误
- java - java.net.ConnectException:从Jenkins部署战争到tomcat时连接被拒绝(连接被拒绝)
- c - C - 格式指定类型“int”,但参数的类型为“char *”[-Wformat]
- c# - C# 从 JSON 响应创建 Deedle DataFrame
- python - 如何从烧瓶中的用户输入中获取表名?
- vert.x - vertx 的自定义指标
- python-3.x - 将“.csv”文件从 Google 驱动器导入 Jupyter 笔记本