Collection Functions in Hive

The following built-in collection functions in Apache Hive.

Size(Map<K.V>): Returns the number of elements in the map type.
Example:
SELECT mobile,places_lived,SIZE(mobile), SIZE(places_lived) FROM ExplodeTest2;

CollectionFunction_Size2

Size(Array<T>):
Returns the number of elements in the array type.
Example:
SELECT SIZE(mobile), SIZE(places_lived) FROM ExplodeTest2;

CollectionFunction_Size

map_keys(Map<K.V>)
It returns an unordered array containing the keys of the input map.

map_values(Map<K.V>)
It returns an unordered array containing the values of the input map.

Example:
SELECT stats,map_keys(stats) from explodetest3;
SELECT stats,map_keys(stats),map_values(stats) from explodetest3;

collection_function_map_keys

Array_Contains(Array<T>, value)
It returns TRUE if the array contains value.

Sort_Array:
Sorts the input array in ascending order according to the natural ordering of the array elements and returns it.

SELECT mobile, sort_array(mobile), places_lived, sort_array(places_lived) from ExplodeTest2;

sort_array_collection_items
a

3 comments

  1. I truly love your blog.. Pleasant colors & theme.
    Did you create this site yourself? Please reply back as I’m
    wanting to create my own blog and would love
    to learn where you got this from or what the theme is called.
    Thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s