Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Returns whether a predicate holds for every element in the array. Supports Spark Connect.
For the corresponding Databricks SQL function, see forall function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.forall(col=<col>, f=<f>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Name of column or expression. |
f |
function |
A function that returns the Boolean expression. |
Returns
pyspark.sql.Column: True if "all" elements of an array evaluates to True when passed as an argument to given function and False otherwise.
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame(
[(1, ["bar"]), (2, ["foo", "bar"]), (3, ["foobar", "foo"])],
("key", "values")
)
df.select(dbf.forall("values", lambda x: x.rlike("foo")).alias("all_foo")).show()
+-------+
|all_foo|
+-------+
| false|
| false|
| true|
+-------+