So there is 3 thing you have change in your process.
- Rename table from MIAC to MIAC_bkup (you did that)
- Rename table location
hdfs:///<some-lcoation>/MIAC
to hdfs:///<some-lcoation>/MIAC_bkup
(which you also did)
- Letting the table know about your new location with below query.
ALTER TABLE MIAC_bkup SET LOCATION "hdfs:///<some-lcoation>/MIAC_bkup"
So when you added data into new MIAC, both backup and new tables are pointing to hdfs:///<some-lcoation>/MIAC
. This is the reason you were seeing data in the backup table added via new table.
Untill here everything should work for you. Even you don’t have to do msck repair.
I believe you don’t have partition, because in that case your issue would be different.
But if the table has partition please follow these additional steps.
In the metadata, hive also stores partition location.
So your existing partition metadata doesn’t know about the location change.
You need to refresh the partition metadata also.
MSCK REPAIR
alone wouldn’t do this job. You have to 1st drop all partition info from metadata then do the MSCK to sync older partition which are in backup location.
-- drop all partiotion
ALTER TABLE MIAC_bkup DROP PARTITION(partition_name <> ''); --refer this to understand
-- repair table
MSCK REPAIR TABLE MIAC_bkup;
NB: MSCK repair doesn’t delete partition, it only adds or checks inconsistency