Saturday 24 December 2022

Hive: explode an array or map into multiple rows

Signature

explode(Array)
expode(Map<K,V>)

Explode an array into multiple rows.

 

Explode map to multiple rows. Once row for each <key, value> pair in the map.

hive> SELECT * FROM emp;
OK
emp.id	emp.name	emp.hobbies	emp.technology_experience	emp.gender_age	emp.rating	emp.salary
1	Hari	["Football","Cricket"]	{"Java":"3.4Yrs","C":"4.5Yrs"}	{"gender":"Male","age":30}	-1.5	1000000.0
2	Chamu	["Trekking","Watching movies"]	{"Selenium":"5.6Yrs"}	{"gender":"Female","age":38}	3.0	2500000.0
3	Sailu	["Chess","Listening to music"]	{"EmbeddedC":"9Yrs"}	{"gender":"Female","age":32}	2.5	1300000.0
4	Gopi	["Cricket"]	{"Datastage":"11Yrs"}	{"gender":"Male","age":32}	-0.7	8.1E7
5	Rahim	[]	{}	{"gender":"Male","age":null}	-0.7	500000.0
Time taken: 0.049 seconds, Fetched: 5 row(s)

Exploding array

hive> SELECT explode(hobbies) FROM emp;
OK
col
Football
Cricket
Trekking
Watching movies
Chess
Listening to music
Cricket
Time taken: 0.063 seconds, Fetched: 7 row(s)

Exploding map

hive> SELECT  explode(technology_experience) FROM emp;
OK
key	value
Java	3.4Yrs
C	4.5Yrs
Selenium	5.6Yrs
EmbeddedC	9Yrs
Datastage	11Yrs
Time taken: 0.044 seconds, Fetched: 5 row(s)






 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment