pyspark.sql.functions.
array_contains
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.
Column
name of column containing array
value or column to check for in array
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)]