一、 静态分区
1.创建静态分区格式:
create table employees (
name string,
salary float,
subordinated array<string>,
deductions map<string,float>,
address struct<street:string,city:string,state:string,zip:int>
) partitioned by (country string,state string)
row format delimited
fields terminated by "\t"
collection items terminated by ","
map keys terminated by ":"
lines terminated by "\n"
stored as textfile;
创建成果后发现他的存储路径和普通的内部表的路径是一样的而且多了分区表的字段,因为我们创建的分区表并没内容,事实上,除非需要优化查询性能,否则实现表的用户不需要关系"字段是否是分区字段"
2.添加分区表 alter table employees add partition (country="china",state="Asia"); 查看分区表信息: show partitions employees; hdfs上的路径:/user/hive/warehouse/zxz.db/employees/country=china/state=Asia 他们都是以目录及子目录形式存储的
3.插入数据: 格式: INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2] ...)] VALUES values_row [