Monday 9 September 2019

Difference between posexplode and explode in Hive



Difference between posexplode and explode in Hive

In the below example, the numbers column has a list of values.


with t1 as (
select 1 as id, 'deepak' as name, '12345, 56789, 7892334, 6263636, 7181818, 1761761717' as numbers )

select * from t1



Explode is used to create multiple rows from a list value in a column. In the below example, you have broken the list in numbers fields into multiple rows.


with t1 as (
select 1 as id, 'deepak' as name, '12345, 56789, 7892334, 6263636, 7181818, 1761761717' as numbers )

select * from t1
LATERAL VIEW explode(split(numbers, ',')) test










PosExplode is used to create multiple rows from a list value in a column. In the below example, you have broken the list in numbers fields into multiple rows along with the column called pos that contains the  position of the value in the list.

with t1 as (
select 1 as id, 'deepak' as name, '12345, 56789, 7892334, 6263636, 7181818, 1761761717' as numbers )

select * from t1
LATERAL VIEW posexplode(split(numbers, ',')) test






No comments:

Post a Comment