hivesql,使用where语句查询数组列

nbewdwxp  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(349)

我只是想在带有array列的表中用where语句过滤查询
例如,我有一列username和usertype,那么每个username可能有多个类型
所以当我使用

select username, collect_set(usertype) as type from table group by username

然后我会有类似的东西:user1,[1,2,3],user2,[3,4,5]等等。问题是当我想使用“where usertype=[3,4,5]”过滤结果时。我不知道如何构造一个数组来进行过滤,现在我一直在使用“where usertype[0]=3 and usertype[1]=4”等等。有人对这件事有什么建议或想法吗?
谢谢

vuv7lop3

vuv7lop31#

不能使用 = .
一种解决办法是 type 使集合 array<string> ,然后使用 concat_ws 要与字符串进行比较: select * from table where concat_ws(' ', usertype) = "1 2 3"; 另一个选项是编写一个比较两个 array<int> 论据。
我在这里找到了几个数组udf的实现,包括arrayequals。

相关问题