How to undo ALTER TABLE … ADD PARTITION without deleting data

时光怂恿深爱的人放手 提交于 2021-01-28 07:07:30

问题


Let's suppose I have two hive tables, table_1 and table_2. I use:

ALTER TABLE table_2 ADD PARTITION (col=val) LOCATION [table_1_location]

Now, table_2 will have the data in table_1 at the partition where col = val.

What I want to do is reverse this process. I want table_2 not to have the partition at col=val, and I want table_1 to keep its original data.

How can I do this?


回答1:


Make your table EXTERNAL first:

ALTER TABLE table_2 SET TBLPROPERTIES('EXTERNAL'='TRUE');

Then drop partition, the data will remain, only table_2 partition metadata will be deleted:

ALTER TABLE table_2 DROP PARTITION (col=val)

table_1 partition data will remain as is.



来源:https://stackoverflow.com/questions/56747307/how-to-undo-alter-table-add-partition-without-deleting-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!