按日期划分的sql配置单元分区?

rta7y2nd  于 2021-06-26  发布在  Hive
关注(0)|答案(3)|浏览(397)

我有一张像这样的外置table

CREATE EXTERNAL TABLE TAB(ID INT, NAME STRING) PARTITIONED BY(YEAR INT, MONTH STRING , DATES INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

我有这样的数据

/user/input/2015/jan/1;
/user/input/2015/jan/30

如2000年至2016年,每年12个月30天;

ALTER TABLE TAB ADD PARTITION(year = '2015', month = 'jan',dates = '5') LOCATION '/user/input/2015/jan/1';

如果我这样做,我只得到一天的数据;

select * from TAB where (year = '2015', month = 'jan',dates = '5');

如果我跑了

select * from TAB where (year = '2015', month = 'jan',dates = '6');

我没有得到任何数据。请帮助我在这个如何改变上述情况下的表

mm9b1k5b

mm9b1k5b1#

alter table with all dates only option,我遵循类似“alter table tab add partition(year='2015',month='jan',dates='5')location'/user/input/2015/jan/1';”

piwo6bdm

piwo6bdm2#

你有1天的假期 ALTER TABLE TAB ADD PARTITION(year = '2015', month = 'jan',dates = '5') LOCATION '/user/input/2015/jan/1'; 因为您在位置值中指定了1个文件
创建分区5天,如下所示

ALTER TABLE TAB 
ADD PARTITION(dates <= '5') 
LOCATION '/user/input/2015/jan/';
qni6mghb

qni6mghb3#

create table tab(id int,name string,dt string) partitioned by (year string,month string);

create table samp(id int,name string,dt string) row format delimited fields terminated by '\t';

load data inpath '\dir' into table samp;
insert overwrite table tab partition (y,m) select id,name dt,YEAR(dt),MONTH(dt) from samp;

相关问题