Below table summarizes the functions that deals with collections.
Function |
Description |
Example |
Return true if array contain this value, else false. |
hive> SELECT hobbies, array_contains(hobbies, 'Cricket') FROM emp; OK hobbies _c1 ["Football","Cricket"] true ["Trekking","Watching movies"] false ["Chess","Listening to music"] false ["Cricket"] true [] false Time taken: 0.07 seconds, Fetched: 5 row(s) |
|
Get all the keys of a map. |
hive> SELECT technology_experience, map_keys(technology_experience) FROM emp; OK technology_experience _c1 {"Java":"3.4Yrs","C":"4.5Yrs"} ["Java","C"] {"Selenium":"5.6Yrs"} ["Selenium"] {"EmbeddedC":"9Yrs"} ["EmbeddedC"] {"Datastage":"11Yrs"} ["Datastage"] {} [] Time taken: 0.05 seconds, Fetched: 5 row(s) |
|
Get all the values of a map. |
hive> SELECT technology_experience, map_values(technology_experience) FROM emp; OK technology_experience _c1 {"Java":"3.4Yrs","C":"4.5Yrs"} ["3.4Yrs","4.5Yrs"] {"Selenium":"5.6Yrs"} ["5.6Yrs"] {"EmbeddedC":"9Yrs"} ["9Yrs"] {"Datastage":"11Yrs"} ["11Yrs"] {} [] Time taken: 0.044 seconds, Fetched: 5 row(s) |
|
Return number of elements in an array |
hive> SELECT hobbies, size(hobbies) FROM emp; OK hobbies _c1 ["Football","Cricket"] 2 ["Trekking","Watching movies"] 2 ["Chess","Listening to music"] 2 ["Cricket"] 1 [] 0 Time taken: 0.051 seconds, Fetched: 5 row(s) |
|
Return number of <key, values> pairs in Hive map |
hive> SELECT size(technology_experience) AS technologies_known from emp; OK technologies_known 2 1 1 1 0 Time taken: 0.043 seconds, Fetched: 5 row(s) |
|
Sort the content of array in ascending order. |
hive> SELECT sort_array(hobbies) FROM emp; OK _c0 ["Cricket","Football"] ["Trekking","Watching movies"] ["Chess","Listening to music"] ["Cricket"] [] Time taken: 0.056 seconds, Fetched: 5 row(s) hive> |
Previous Next Home
No comments:
Post a Comment