Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop all partitions from a hive table?

How can I drop all partitions currently loaded in a Hive table?

I can drop a single partition with alter table <table> drop partition(a=, b=...);

I can load all partitions with the recover partitions statement. But I cannot seem to drop all partitions.

I'm using the latest Hive version supported by EMR, 0.8.1.

like image 289
Matt Joiner Avatar asked Mar 19 '13 05:03

Matt Joiner


People also ask

How do I delete old partitions in Hive?

Hive drop or delete partition is performed using ALTER TABLE tablename DROP command. Dropping a partition from a table removes the data from HDFS and from Hive Metastore.

How delete all partitions from a table in Oracle?

You have to use pl/sql block for dropping partitions from a table with select query. Use listagg for making a comma separated list. Show activity on this post. You may use the following sql to generate DML for dropping multiple table partitions.

How do I drop a column from a partitioned table in Hive?

You cannot drop column directly from a table using command ALTER TABLE table_name drop col_name; The only way to drop column is using replace command.


1 Answers

As of version 0.9.0 you can use comparators in the drop partition statement which may be used to drop all partitions at once.

An example, taken from the drop_partitions_filter.q testcase :

create table ptestfilter (a string, b int) partitioned by (c string, d string);
alter table ptestfilter add partition (c='US', d=1);
alter table ptestfilter add partition (c='US', d=2);
alter table ptestFilter add partition (c='Uganda', d=2);
alter table ptestfilter add partition (c='Germany', d=2);
alter table ptestfilter add partition (c='Canada', d=3);
alter table ptestfilter add partition (c='Russia', d=3);
alter table ptestfilter add partition (c='Greece', d=2);
alter table ptestfilter add partition (c='India', d=3);
alter table ptestfilter add partition (c='France', d=4);

show partitions ptestfilter;
alter table ptestfilter drop partition (c>'0', d>'0');
show partitions ptestfilter;
like image 51
Lorand Bendig Avatar answered Oct 19 '22 02:10

Lorand Bendig