我如何删除Hive表中当前加载的所有分区?
我可以使用alter table <table> drop partition(a=, b=...);
命令来删除单个分区。
我可以使用“recover partitions”语句加载所有分区。但是我似乎无法删除所有分区。
我正在使用EMR支持的最新Hive版本0.8.1。
我如何删除Hive表中当前加载的所有分区?
我可以使用alter table <table> drop partition(a=, b=...);
命令来删除单个分区。
我可以使用“recover partitions”语句加载所有分区。但是我似乎无法删除所有分区。
我正在使用EMR支持的最新Hive版本0.8.1。
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;
Hive允许您在选择分区时使用比较运算符(例如>
,<
,=
,<>
)。例如,以下语句应删除表中的所有分区。
ALTER TABLE table_name DROP PARTITION (partition_name > '0');
create table t2 as
select * from t1;
删除旧表 t1
drop table t1;
现在检查一下新表上是否有分区。
show partitions t2;
使用原始表中的数据创建表:
CREATE TABLE t2 AS
SELECT column_name_1, ..., column_name_N FROM t1;
唯一的情况是它必须在非严格模式下完成:
set hive.mapred.mode=nonstrict;
希望能对你有所帮助。祝好运!
truncate table table_name;
将删除所有分区。如果您想删除分区表,这将非常有用。
FAILED: Error in semantic analysis: 1:23 Need to specify partition columns because the destination table is partitioned. Error encountered near token 't1'
- Matt Joiner