Hive3分区表增删改查

21 篇文章 2 订阅

创建分区表

create table student_par(id int,name string)
partitioned by (class string) 
row format delimited fields terminated by '\t';

加载数据

load data local inpath '/opt/module/hive/datas/student.txt' into table student_par partition(class='class01');

insert into table student_par partition(class="class02") select * from student; 

insert overwrite table student_par partition(class="class02") select * from student where id=1001;

查询指定分区数据

select * from student_par where class='class01';

增加分区

alter table student_par add partition(class="class03");

alter table student_par add partition(class="class04") partition(class="class05");

查看表所有分区

show partitions student_par;

删除分区

alter table student_par drop partition(class="class03");

alter table student_par drop partition(class="class04"),partition(class="class05");

创建二级分区

create table student_par2(id int,name string)
partitioned by (class string,grade string)
row format delimited fields terminated by '\t';

加载数据

load data local inpath '/opt/module/hive/datas/student.txt' into table student_par2 partition(class='class01',grade="1");

修复分区数据不显示

-- 方式1 上传数据后修复
msck repair table student_par2;
-- 方式2 上传数据后添加对应分区
alter table student_par2 add partition(class='class01',grade="2");
-- 方式3 上传数据同时指定分区
load data local inpath '/opt/module/hive/datas/student.txt' into table student_par2 partition(class='class01',grade='3'); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值