pyspark.sql.functions.array_contains

pyspark.sql.functions.array_contains(col: ColumnOrName, value: Any) → pyspark.sql.column.Column[source]

Collection function: returns null if the array is null, true if the array contains the given value, and false otherwise.

New in version 1.5.0.

Parameters
colColumn or str

name of column containing array

value :

value or column to check for in array

Examples

>>> df = spark.createDataFrame([(["a", "b", "c"],), ([],)], ['data'])
>>> df.select(array_contains(df.data, "a")).collect()
[Row(array_contains(data, a)=True), Row(array_contains(data, a)=False)]
>>> df.select(array_contains(df.data, lit("a"))).collect()
[Row(array_contains(data, a)=True), Row(array_contains(data, a)=False)]