HIVE - INSERT OVERWRITE vs DROP TABLE + CREATE TABLE + INSERT INTO

前端 未结 2 1641
粉色の甜心
粉色の甜心 2020-12-16 17:02

I\'m doing some automatic script of few queries in hive and we found that we need time to time clear the data from a table and insert the new one. And we are thinking what c

相关标签:
2条回答
  • 2020-12-16 17:49

    For maximum speed I would suggest to 1) issue hadoop fs -rm -r -skipTrash table_dir/* first to remove old data fast without putting files into trash because INSERT OVERWRITE will put all files into Trash and for very big table this will take a lot of time. Then 2) do INSERT OVERWRITE command. This will be faster also because you do not need to drop/create table.

    UPDATE:

    As of Hive 2.3.0 (HIVE-15880), if the table has TBLPROPERTIES ("auto.purge"="true") the previous data of the table is not moved to Trash when INSERT OVERWRITE query is run against the table. This functionality is applicable only for managed tables. So, INSERT OVERWRITE with auto purge will work faster than rm -skipTrash + INSERT OVERWRITE or DROP+CREATE+INSERT because it will be a single Hive-only command.

    0 讨论(0)
  • 2020-12-16 18:07

    One edge consideration is that if your schema changes, INSERT OVERWRITE will fail, while DROP+CREATE+INSERT will not. While this is unlikely to apply in most scenarios, if you're prototyping workflow/table schemas then it might be worth considering.

    0 讨论(0)
提交回复
热议问题