size function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns the cardinality of the array or map in expr.

Syntax

size(expr)

Arguments

  • expr: An ARRAY or MAP 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