web-dev-qa-db-ja.com

Hiveテーブルからすべてのパーティションを削除しますか?

現在Hiveテーブルにロードされているすべてのパーティションを削除するにはどうすればよいですか?

alter table <table> drop partition(a=, b=...);で1つのパーティションを削除できます

私はrecoverpartitionsステートメントでallパーティションをロードできます。しかし、すべてのパーティションを削除することはできないようです。

EMRでサポートされている最新のHiveバージョン0.8.1を使用しています。

14
Matt Joiner

バージョン0.9.0以降、すべてのパーティションを一度にドロップするために使用できるdroppartitionステートメントで comparators を使用できます。

drop_partitions_filter.q テストケースからの例:

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;
20
Lorand Bendig

Hiveを使用すると、比較演算子を使用できます(例:><=<>)パーティションを選択するとき。たとえば、次のようにすると、テーブル内のすべてのパーティションが削除されます。

ALTER TABLE table_name DROP PARTITION (partition_name > '0');
13
Jonathan

以下のように、既存のテーブルt1から新しいテーブルt2を作成します。

 create table t2 as
    select * from t1;

古いテーブルt1を削除します

drop table t1;

ここで、新しいテーブルにパーティションがあるかどうかを確認します。

show partitions t2;
3


元のテーブルのデータを使用してテーブルを作成します。

CREATE TABLE t2 AS
SELECT column_name_1, ..., column_name_N FROM t1;

唯一のケースは、非厳密モードで実行する必要がある場合です。

set Hive.mapred.mode=nonstrict;

お役に立てば幸いです。 GL!

0
www