Hive分割槽表增刪改查
阿新 • • 發佈:2021-02-20
建立分割槽表
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');