【发布时间】:2013-12-05 16:41:45
【问题描述】:
我们就在 case 子句中使用正则表达式的最佳方式进行了辩论... 我们需要对提取的对象进行案例操作。 这可以用几种方式表达。 问题是:哪个更有效?如果正则表达式出现在多个位置,BQ 会多次处理它吗?
我已调整我的代码以在维基百科数据示例上运行。
第一个:
Select case when PS_Version='1' then '1st'
when PS_Version='2' then '2nd'
when PS_Version='3' then '3rd'
else 'other' end as PS_VersionOrder
from
(SELECT regexp_extract(title,r'PlayStation (\d+)') as PS_Version
FROM [publicdata:samples.wikipedia] A
where title like '%PlayStation%'
limit 100)
第二个:
Select case when regexp_extract(title,r'PlayStation (\d+)')='1' then '1st'
when regexp_extract(title,r'PlayStation (\d+)')='2' then '2nd'
when regexp_extract(title,r'PlayStation (\d+)')='3' then '3rd'
else 'other' end as PS_VersionOrder
FROM [publicdata:samples.wikipedia] A
where title like '%PlayStation%'
limit 100
人们声称第一个正则表达式会更有效率。数据库人更喜欢第二个,因为它不涉及子查询...
【问题讨论】:
标签: regex google-bigquery