Skip to content

When to use lateral view explode in hive

if you have a table with one or more column with array datatype  and if you want it to expand into multiple rows, you can use lateral view explode function. 

Let’s consider we have following table, where one employee has multiple phone numbers which are stores as part of array (list). 

emp_namephone_numbers
user1[“546-487-3384″,”383-767-2238”]
user2[“373-384-1192″,”374-282-1289″,”332-453-5566”]

However as a output if we want to convert this Array (list) into multiple rows, we can use lateral view explode function a mentioned below 

select emp_name, phone_number 
from 
    temp.test_laterla_view_explode
lateral view explode(phone_numbers) p as phone_number

This will generate the output as mentioned below

emp_namephone_number
user2373-384-1192
user2374-282-1289
user2332-453-5566
user1546-487-3384
user1383-767-2238
Published inHadoophive

One Comment

  1. LATERAL VIEW is often used with explode, but explode is just one UDTF of many, a full list is available in the

Leave a Reply

Your email address will not be published. Required fields are marked *