-
静态分区表(导入linux本地的数据)
- partitioned by(分区字段,字段类型),分区字段不能和表字段一样
- 静态分区需要手动导入数据和人为划分数据文件
- 静态分区:需要有原始数据表,分区表,分区表和原始表的定义字段要保持一致
- 将原始数据表汇总的数据内容根据分区指定的分区字段自动进行分区
create table test_tb_part ( id int, name string, age int, gender string ) partitioned by (sex string) row format delimited fields terminated by ','; load data local inpath '/root/boy.txt' into table test_tb_part partition (sex='boy'); load data local inpath '/root/girl.txt' into table test_tb_part partition (sex='girl');
-
动态分区表(可以根据指定的字段动态进行分区操作)
create table test_tb_part_D( id int, name string, age int, gender string )partitioned by (sex string) row format delimited fields terminated by ','; -- 设置允许动态分区写入 set hive.exec.dynamic.partition.mode=nonstrict; insert into table test_tb_part_D partition (sex) select t.id,t.name,t.age,t.gender, t.gender from test_tb_f as t;
-
查看分区详情
desc formatted test_tb_part;
-
查看已经产生的分区
show partitions test_tb_part;
-
删除分区
alter table test_tb_part drop partition (sex='girl');
-
删除分区表
drop table test_tb_part_D;
-
修改分区
alter table test_tb_part add partition (sex='aa');
-
修改分区名称
alter table test_tb_part partition (sex='aa') rename to partition (sex='bb');
-
修改分区路径
alter table test_tb_part partition (sex='aa') set location '/ming';
-
在hdfs上创建了一个分区,而不是通过alter table test_tb_part add partityion(sex=‘aa’);创建的分区,hdfs创建的分区不会添加到元数据中
msck repair table test_tb_part;



