size
Collection function: Returns the length of the array or map stored in the column. Supports Spark Connect.
For the corresponding Databricks SQL function, see size function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.size(col=<col>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Name of column or expression. |
Returns
pyspark.sql.Column: length of the array/map.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([([1, 2, 3],),([1],),([],)], ['data'])
df.select(dbf.size(df.data)).collect()
Output
[Row(size(data)=3), Row(size(data)=1), Row(size(data)=0)]