size function

Returns the cardinality of the array or map in expr.

Syntax

size(expr)

Arguments

  • expr: An ARRAY or MAP expression.

Returns

An INTEGER.

Note

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);
 NULL