Hive分区

创建分区表 

dt 是分区列

create table pt1 (id int, name string) partitioned by (dt string) row format delimited fields terminated by ',' stored as textfile;

增加分区

alter table pt1 add partition (dt='2018-07-13');

删除分区

alter table pt1 drop partition(dt='2018-07-13');

导入分区数据

准备数据 pt1-2018-07-13.txt 和 pt1-2018-07-14.txt

Hive分区_第1张图片

导入数据

load data local inpath 'E:\hive\pt1-2018-07-13.txt' overwrite into table pt1 partition (dt='2018-07-13');
load data local inpath 'E:\hive\pt1-2018-07-14.txt' overwrite into table pt1 partition (dt='2018-07-14');

查看hdfs

Hive分区_第2张图片

hdfs查询分区

 hadoop fs -ls /user/hive/warehouse/pt1
    drwxrwxr-x   - admin supergroup          0 2018-07-13 16:02 /user/hive/warehouse/pt1/dt=2018-07-13
    drwxrwxr-x   - admin supergroup          0 2018-07-13 16:03 /user/hive/warehouse/pt1/dt=2018-07-14

hdfs显示分区信息

hdfs dfs -cat /user/hive/warehouse/pt1/dt?2018-07-13/pt1-2018-07-13.txt

本机环境hadoop-2.7.6目录不支持=号,查询时用代替

hive查询分区数据

select * from pt1
where dt = '2018-07-14'
limit 10;


你可能感兴趣的:(大数据)