如何使用 Apache Spark SQL 查询在字符串数组中搜索字符串?

How to search a string in an array of strings using Apache Spark SQL query?

我有一个这样的字符串数组:

SELECT ARRAY('item_1', 'item_2', 'item_3') AS items

结果:

items
Type : ARRAY<STRING>
["item_1","item_2","item_3"]

我想在其中搜索某个项目,但如果我尝试常规方式:

SELECT * FROM items WHERE items = 'item_1'

我会得到这个错误:

Cannot resolve '(items.items = 'item_1')' due to data type mismatch differing types in '(items.items = 'item_1')' (array and string). line 1 pos 26

那么,如何使用 Spark SQL 查询在字符串数组中搜索字符串值?

提前致谢=)

使用array_contains函数:

SELECT * FROM items WHERE array_contains(items, 'item_1')