创建外部分区表

create  external table if not exists 表名 (
id int comment '唯一id',
name string comment '姓名',
age string commnet '年龄'
)partitioned by(dt string);

不指定表的路径默认存放在hdfs默认路径下

1.给表添加分区

alter table 表名 add if not exists partition(dt='2021-11-11');

2.添加分区时指定分区读取hdfs上的文件路径

(不指定分区默认读取表文件路径下的分区路径)

alter table table1 add if not exists partition(dt='2021-11-11') location '/dws/table1/dt=2021-11-12';

这样添加的分区虽然是dt=2021-11-11 但是会读取   /dws/table1/dt=2021-11-12 文件下的数据

3.删除分区

alter table 表名 drop if exists partition(dt='2022-05-06');

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐