hive按年月实现动态分区

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

创建动态分区表:testtable1

CREATE TABLE testtable1(
   id string, 
   date string)
 partitioned by (month string)
 row format delimited fields terminated by '\t';

创建普通表:testtable2

CREATE TABLE testtable1(
   id string, 
   date string)
 row format delimited fields terminated by '\t';

向普通表插入数据testtable2:

insert into table testtable2 values('1','201908');

insert into table testtable2 values('1','201907');

把testtable2表数据插入testtable1

insert overwrite table testtable1 partition(month)
 select *,date as month
 from testtable2;

查看testtable1表分区有两个分区---201907和201908

新建testtable3表

CREATE TABLE testtable3(
   id string, 
   date string)
 row format delimited fields terminated by '\t';

插入数据

insert into table testtable3 values('3','20190610');

把testtable3表数据插入到testtable1中

insert overwrite table testtable1 partition(month)
 select *,substring(date,1,6) as month
 from testtable3;

查看分区有三个分区:

show partitions testtable1;

发布了43 篇原创文章 · 获赞 34 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/lin443514407lin/article/details/95324471