Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete/truncate tables from Hadoop-Hive?

Tags:

hadoop

hive

Please tell me how to delete table from hive and also tell from where i can get more information about hive queries.

like image 807
Amol Fasale Avatar asked Feb 28 '13 08:02

Amol Fasale


People also ask

How do I delete table data in Hive?

DROP TABLE command in the hive is used to drop a table inside the hive. Hive will remove all of its data and metadata from the hive meta-store. The hive DROP TABLE statement comes with a PURGE option.

How do you truncate a table in Hive?

Truncating a table in Hive is indirectly removing the files from the HDFS as a table in Hive is just a way of reading the data from the HDFS in the table or structural format. The general format of using the Truncate table command is as follows: TRUNCATE TABLE table_name [PARTITION partition_spec];

Can you truncate the external table in Hive?

You cannot delete or truncate an external table. However, you can alter and drop the table definition. Dropping an external table drops the table definition, but it does not delete the data file that is associated with the table.


2 Answers

You can use drop command to delete meta data and actual data from HDFS.

And just to delete data and keep the table structure, use truncate command.

For further help regarding hive ql, check language manual of hive.

like image 168
Balaswamy Vaddeman Avatar answered Oct 20 '22 20:10

Balaswamy Vaddeman


To Truncate:

hive -e "TRUNCATE TABLE IF EXISTS $tablename"

To Drop:

hive -e "Drop TABLE IF EXISTS $tablename"
like image 23
Anoop Velluva Avatar answered Oct 20 '22 20:10

Anoop Velluva