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.
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
from pyspark.databricks.sql import functions as dbf
dbf.size(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Name of column or expression. |
Returns
pyspark.sql.Column: length of the array/map.
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([([1, 2, 3],),([1],),([],)], ['data'])
df.select(dbf.size(df.data)).collect()
[Row(size(data)=3), Row(size(data)=1), Row(size(data)=0)]