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.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

name of column containing array

value

value or column to check for in array

Returns
Column

a column of Boolean type.

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)]