I'm planning to truncate the hive external table which has one partition. So, I have used the following command to truncate the table :
hive> truncate table abc;
But, it is throwing me an error stating : Cannot truncate non-managed table abc.
Can anyone please suggest me out regarding the same ...
This notion of partitioning is an old one, distributing the load horizontally and moving data closer to the user. Both external and managed (or internal) tables can be partitioned in Hive.
An external table is generally used when data is located outside the Hive. Let us create an external table using the keyword “EXTERNAL” with the below command. An external table can also be created by copying the schema and data of an existing table, with below command:
If it does not delete the data you will need to delete the directory of the partition (in HDFS) after deleting it using the Hive query. You can use PURGE option to delete data file as well along with partition mentadata but it works only in INTERNAL/MANAGED tables
So, dropping a Hive managed table drops schema, metadata & data. However, an external table has data sitting somewhere else (let's say external source such as S3). So, dropping the table only drops the metadata and the table but data remains intact in the source.
Make your table MANAGED
first:
ALTER TABLE abc SET TBLPROPERTIES('EXTERNAL'='FALSE');
Then truncate:
truncate table abc;
And finally you can make it external again:
ALTER TABLE abc SET TBLPROPERTIES('EXTERNAL'='TRUE');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With