如何在Impala中的LIKE语句中使用子查询?

How to use subquery in LIKE statement in Impala?

我有一个包含 forbidden values/strings 的查找 table 和一个描述该值不能出现的位置的规则编号。因此,例如,我将“C/O”作为值,这不能出现在名称字段中的任何位置。我还有不能出现在地址中的‘P.O’。我正在尝试创建一个数据质量报告来标记这些值而无需硬编码。我试过:

Select 
A.name
,A.address
From customer A
Where a.name LIKE (Select concat(‘%’, exclusion_value, ‘%’) from DQ_lookup where rule_number=2)
Or a.address LIKE (Select concat(‘%’, exclusion_value, ‘%’) from DQ_lookup where rule_number=1)

这失败了。如果我完全可以让它工作怎么办?

要在配置单元中匹配模式,您需要使用 rlike

A RLIKE B : NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java regular expression B, otherwise FALSE. For example, 'foobar' RLIKE 'foo' evaluates to TRUE and so does 'foobar' RLIKE '^f.*r$'.

如下所示即可。

Select 
 A.name,
 A.address
From customer A
Where 
 a.name RLIKE (Select exclusion_value from DQ_lookup where rule_number=2)
 OR a.address RLIKE (Select exclusion_value from DQ_lookup where rule_number=1)

注意:exclusion_value应该是正则表达式。