14

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

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

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

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

4

5 に答える 5

23

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

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;
于 2013-03-19T08:49:49.943 に答える
14

Hive では、パーティションを選択するときに比較演算子 ( ><=など) を使用できます。<>たとえば、次はテーブル内のすべてのパーティションを削除する必要があります。

ALTER TABLE table_name DROP PARTITION (partition_name > '0');
于 2014-11-08T01:11:34.007 に答える
0


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

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

非厳密モードで実行する必要がある場合のみ:

set hive.mapred.mode=nonstrict;

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

于 2013-03-19T13:01:15.997 に答える
-3
truncate table table_name; 

すべてのパーティションを削除します。これは、分割されたテーブルを削除する場合に特に便利です。

于 2016-02-12T10:38:32.977 に答える