Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to merge source records with existing records in Hive ?

Highlighted

How to merge source records with existing records in Hive ?

New Contributor

I want to merge source records from hive existing records based on some key and if records exist in hive table then only update the value of particular records. Example :

i have a table in hive "Test" with records-1 (id : 1, name : abc, age : 20), records-2 (id : 2, name : xyz, age : 22)

and i am getting the records from source (live sensor ). The same records i am getting from the sensor and doing some merge based on id, so if the records matched with existing records from hive table then only update new value else insert the key and value both.

I want the way in java coding only, query i have for merging the records.

merge into customer_name
	using ( select * from all_updates) sub
	on sub.id = customer_name.id
	when matched then update set name = sub.name, state = sub.state
	when not matched then insert values (sub.id, sub.name, sub.state);


I did in java but not finding the way how to resolve this issue. Could anybody suggest me the way.


Thanks.

Don't have an account?
Coming from Hortonworks? Activate your account here