Hive_分区表

家住魔仙堡 提交于 2019-12-03 12:11:54

分区表实际上就是对应一个HDFS文件系统上的独立的文件夹,该文件夹下是该分区所有的数据文件。Hive中的分区就是分目录,把一个大的数据集根据业务需要分割成小的数据集。在查询时通过WHERE子句中的表达式选择查询所需要的指定的分区,这样的查询效率会提高很多。

分区表基本操作

1.引入分区表(需要根据日期对日志进行管理)

/user/hive/warehouse/log_partition/20170702/20170702.log
/user/hive/warehouse/log_partition/20170703/20170703.log
/user/hive/warehouse/log_partition/20170704/20170704.log

2.创建分区表语法

hive (default)> create table dept (
deptno int, dname string, loc string
)
partitioned by (month string)
row format delimited fields terminated by '\t';

注意:分区字段不能是表中已经存在的数据,可以将分区字段看作表的伪列。

3.加载数据到分区表中

hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table default.dept partition(month='201709');
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table default.dept partition(month='201708');
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table default.dept partition(month='201707’);

注意:分区表加载数据时,必须指定分区

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!