我有一个查找表,其中包含禁止的值/字符串和一个规则号,其中描述了不能出现该值的位置。因此,例如,我以“C / 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应该是一个正则表达式。
关于hadoop - 如何在Impala的LIKE语句中使用子查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62892669/