HIVE SQL Collapsing continuous ranges into single rows HIVE SQL Collapsing continuous ranges into single rows hadoop hadoop

HIVE SQL Collapsing continuous ranges into single rows


This can be achieved with a difference of row numbers approach. To understand how it works, run the inner query and look at the results.

select name,id,min(day),max(day)from (select t.*,      row_number() over(order by day)      -row_number() over(partition by name,id order by day) as grp      from tbl t     ) tgroup by name,id,grp