有没有办法在 HiveQL 中对数组使用 like 运算符?

Is there a way to use like operator with an array in HiveQL?

我正在寻找一种使用 like 运算符查询具有多个值的 collect_set/list 列的方法。 在下面的示例中,我希望获得具有 values like '121%'

之一的行
id values
1 ["8001","12100"]
2 ["12134","9999","2222"]
3 NULL
4 ["5671","9765]

结果:

id values
1 ["8001","12100"] -- because of 121 in 2nd value of the collect_set
2 ["12134","9999","2222"] -- because of 121 in first value of the collect_set

如有任何帮助,我们将不胜感激。谢谢

使用一些定界符连接数组,例如 | 并在 RLIKE 运算符中使用连接字符串。

演示:

with mytable as (
select 1 id, array('8001','12100') as `values`
union all
select 2, array('12134','9999','2222')
union all
select 3, array() 
union all
select 4, array('5671','9765') 
)
select * from mytable
where concat('|',concat_ws('|',`values`),'|') rlike '\|121'

结果:

id  values
1   ["8001","12100"]
2   ["12134","9999","2222"]

注意:正则表达式中的管道 | 需要用双反斜杠转义。