如何在配置单元上对未分区的表进行分区?

dy2hfwbg  于 2021-06-26  发布在  Impala
关注(0)|答案(2)|浏览(359)

给定一个包含360天数据的表,我们希望按日期对其进行分区以提高性能。我们需要为每个日期使用以下select命令吗?还有更有效的方法吗?

INSERT INTO TABLE <new_table> Partition (dt='2015-07-01')
SELECT * from <table> WHERE dt='2015-07-01'
1wnzp6jl

1wnzp6jl1#

先整理table:

create  db.my_table(column1 int, column2 string,
                     -- ...
)
comment 'I like paritioned tables'
partitioned by(dt string)
location '/path/to/file';

现在可以将数据加载到dt分区中:

insert overwrite into table db.my_table partition (dt) select * from other_table;
iqxoj9l9

iqxoj9l92#

如果新表是按dt(date)分区的,那么应该使用动态分区。您不需要指定特定的分区(在本例中是date)。通过这种方式,hive实现了所有不同的日期,并自动进行分区。
记住设置这些标志:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

相关问题