Function tips for collections

The size(...) function is used to calculate the collection size for the MAP, ARRAY, or nested MAP/ARRAY. It returns -1 if the collection is NULL and returns 0 if the collection is empty, as follows:

> SELECT > SIZE(work_place) as array_size,> SIZE(skills_score) as map_size,> SIZE(depart_title) as complex_size,> SIZE(depart_title["Product"]) as nest_size> FROM employee;+-------------+-----------+---------------+------------+| array_size  | map_size  | complex_size  | nest_size  |+-------------+-----------+---------------+------------+| 2           | 1         | 1             | 2          || 1           | 1         | 2             | 1          || 1           | 1         | 2             | -1         || 1           | 2         | 1             | -1         |+-------------+-----------+---------------+------------+4 rows selected (0.062 seconds)> SELECT size(null), size(array(null)), ...

Get Apache Hive Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.