1创建分区
A、单分区建表语句:
hive> create table day_table(id int,
> content string)
> partitioned by (dt string)
> row format delimited foelds terminated by ',';
【单分区表,按天分区,在表结构中存在id,content,dt三列;以dt为文件夹区分】
B、双分区建表语句:
hive> create table day_hour_table(id int,
> content string)
> partitioned by (dt string,hour string)
> row format delimited foelds terminated by ',';
【双分区表,按天和小时分区,在表结构中新增加了dt和hour两列;先以dt为文件夹,再以hour子文件夹区分】
注意:在创建 删除多分区等操作时一定要注意分区的先后顺序,他们是父子节点的关系。分区字段不要和表字段相同。
2.添加表里面的分区
hive> alter table day_hour_table add partition (dt='2008-02-08', hour='07');
3.删除分区
hive> alter table day_hour_table drop partition (dt='2008-02-08',hour='07');