1 把数据直接上传到分区目录上,让分区表和数据产生关联的三种方式
1.1 上传数据后修复
- 上传数据
dfs -mkdir -p /user/dept_partition/day=20210725/hour=8
dfs -put /opt/apps/dept_20210725.log /user/dept_partition/day=20210725/hour=8
- 查询数据
select * from dept_partition where day=‘20210725’ and hour=‘8’
查询不到
- 修复数据
msck repair table dept_partition;
- 再次查询数据
select * from dept_partition where day=‘20210725’ and hour=‘8’
1.2 上传数据后添加分区
- 上传数据
dfs -mkdir -p /user/dept_partition/day=20210725/hour=8
dfs -put /opt/apps/dept_20210725.log /user/dept_partition/day=20210725/hour=8
- 添加分区
alter table ddept_partition add partition(day=‘20210725’,hour=‘8’)
- 查询数据
select * from dept_partition where day=‘20210725’ and hour =‘8’
1.3 创建文件夹后load数据到分区
- 上传数据
dfs -mkdir -p /user/dept_partition/day=20210725/hour=8
- 上传数据
load data local inpath ‘/opt/apps/dept_20210725.log’ into table dept_partiton partition(day=‘20210725’,hour=‘8’)
- 查询数据
select * from dept_partition where day=‘20210725’ and hour =‘8’