Monday, June 19, 2017

Hive-Merging tables

Merging tables
--------------
union
unionall


union merges 2 tables but doesn't allow duplicates.
union all merges 2 tables, allow duplicates.
union is not suppoted in hive.

while applying unionall we should apply a subquery along with an alias.

create table tab1(line string);
insert into tab1 values('Manohar is Good person');

create table tab2(line string);
insert into tab2 values('Manohar lives for teaching');

create table tab3(line string);
hive> insert overwrite table tab3
    > select * from(
    > select *from tab1
    > union all
    > select *from tab2) tab;





Assignment
----------
Merging 2 tables into a table with same cols
Merging 2 tables into a table with  change in cols order.
Merging 2 tables into a table with  change in table strcuture.


No comments: