Support Questions
Find answers, ask questions, and share your expertise

How to merge source records with existing records in Hive ?


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 =
	when matched then update set name =, state = sub.state
	when not matched then insert values (,, sub.state);

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