一、 静态分区
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 [, values_row …]; 格式2:(推荐使用) load data local inpath '/home/had/data1.txt' into table employees partition (cou

本文详细介绍了Hive中的静态分区和动态分区操作,包括创建、添加、查询、修改和删除分区,以及数据的加载与迁移。通过示例展示了如何使用CTAS语句、外部表和动态分区功能,强调了动态分区在处理大量数据时的效率优势,并提供了开启动态分区的相关设置。此外,还讨论了分区表在数据管理和查询优化中的作用。
最低0.47元/天 解锁文章
332

被折叠的 条评论
为什么被折叠?



