如何在Hive中执行不区分大小写的array_contains子句

时间:2017-05-11 15:58:52

标签: hadoop hive hiveql

我有一个看起来像这样的配置单元查询:

select * from table_name where array_contains(field_name, '${some_variable}');

这没有任何问题,但区分大小写。我需要它不区分大小写,但两者都

select * from table_name where array_contains(lower(field_name), '${some_variable}');

select * from table_name where array_contains(lcase(field_name), '${some_variable}');

因空指针异常而失败。有没有办法使这个查询不区分大小写?

1 个答案:

答案 0 :(得分:1)

with t as (select array('X','y','Z') as field_name, 'Y' as var)
select  array_contains(split(lower(concat_ws('\u0001',field_name)),'\u0001'),lower(var))
from    t

with t as (select array('X','y','Z') as field_name, 'Y' as var)
select  concat_ws('\u0001',field_name) rlike concat('(?i)(^|\\x01)',var,'(\\x01|$)')
from    t