Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to truncate a partitioned external table in hive?

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 ...

like image 202
fervent Avatar asked Nov 12 '18 06:11

fervent


People also ask

What is table partitioning in hive?

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.

How to create an external table 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:

How do I delete data from a partition in hive?

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

What happens to data when you drop a hive table?

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.


1 Answers

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');
like image 177
leftjoin Avatar answered Sep 19 '22 17:09

leftjoin