简体   繁体   中英

truncate command ( Hive vs SQL)

I was expecting the same behavior of truncate in SQL and HIVE. But its different. I want to confirm if I am perceiving it wrongly

1) In SQL, The following command drop table and create again. All partitions are dropped if exist

mysql> truncate table t1;

2) In HIVE, The following command just delete the data from the table. It do not drop the existing partitions. We need to drop it manually.

hive> truncate table t1;

I found one more issue, If we add column to a partitioned table with altering it. Then there will be a problem in insert overwrite data to the table. Work around found was to drop all the existing partitions on the table.

Is it a issue in HIVE(version 0.13)? What are the other difference in using truncate for HIVE and SQL?

In HIVE truncate table will Removes all rows from a table or partition(s).

The partitions won't get remove.We have to manually drop those partitions.

Currently target table should be native/managed table or exception will be thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM