size
function
Applies to: Databricks SQL Databricks Runtime
Returns the cardinality of the array or map in expr
.
Syntax
size(expr)
Arguments
expr
: AnARRAY
orMAP
expression.
Returns
An INTEGER
.
Note
In Databricks Runtime, if spark.sql.ansi.enabled is false
, size(NULL)
returns -1
instead of NULL
.
Examples
> SELECT size(array('b', 'd', 'c', 'a'));
4
> SELECT size(map('a', 1, 'b', 2));
2
> SELECT size(NULL);
-1