hive 动态分区实现 (hive-1.1.0)
笔者使用的hive版本是hive-1.1.0
hive-1.1.0动态分区的默认实现是只有map没有reduce,通过执行计划就可以看出来。(执行计划如下)
insert overwrite table public_t_par partition(delivery_datekey) select * from public_oi_fact_partition;
hive 默认的动态分区实现,不需要shuffle
那么hive如何通过map就实现了动态分区了呢,stage1根据FileInputSplit决定有几个map,假如数据量较少只有一个map,这个job是没有reduce的,那么就不会有sort merge combine等操作。
假设这个map读的数据有10基数的delivery_datekey
,那么这个map每读到一个不同delivery_datekey
数据就会打开一个file writer,一共会打开十个file writer。其实是相当浪费文件句柄的。这也就是为什么hive 严格模式是禁止用动态分区的,就算关闭严格模式,也是限制job最大写分区数的,甚至限制每台节点写分区数,就是怕某个动态分区的hive任务把系统的文件句柄耗光,影响其他任务的正常运行。
当stage1 map把数据写到相关分区后,再由stage 2启动分区数(其实小于等于生成的分区数)个map进行小文件的合并。由于我们stage1 只有一个map不会涉及每个分区下有多个文件,并不用启动stage2,进行分区下小文件合并。
hive 优化后动态分区实现,开启reduce,需要shuffle
# 使用这个参数开始动态分区优化,其实就是强制开启reduce
SET hive.optimize.sort.dynamic.partition=true;
实现思路就是把分区字段
delivery_datekey
作为key(细节可能跟源码有出入,因为没看源码,不过这里怎么实现都行,就看源码想不想根据其他字段排序了,不影响整体理解),其他字段作为value,也根据分区字段delivery_datekey
分区partition,然后通过shuffle传到不同的reduce,这样合并小文件的操作有reduce完成了。一个reduce会写多个分区(不会出现小文件问题)。
两种实现方式有个优缺点,稍后总结一下
# 总结
未完待续...
还有就是如果目标表是 orc 或者 parquet 使用动态分区有时会出现java heap oom
稍后说下原因:
未完待续...
解决方案
如果出现oom,说明使用的是hive默认实现方式并且用了orc或parquet作为target 表的格式。
1. 开始强制开启reduce,可以解决
SET hive.optimize.sort.dynamic.partition=true;
2. 减小maxSplit,相当于把map数变多,让分区基数分散到多个map上,减少单个map的内存压力,不过这个跟数据分布也有关。
set mapred.max.split.size 设置一个小于128m的数
3. 增大map 的堆内存空间。
mapreduce.map.memory.mb和 mapreduce.map.java.opts
# hive 想使用动态的参数,后两个参数根据集群情况自己设置合适的值
set hive.mapred.mode=nonstrict;
SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.max.dynamic.partitions.pernode = 1500;
SET hive.exec.max.dynamic.partitions=3000;
hive (public)> explain insert overwrite table public_t_par partition(delivery_datekey) select * from public_oi_fact_partition;
OK
STAGE DEPENDENCIES:
Stage-1 is a root stage
Stage-7 depends on stages: Stage-1 , consists of Stage-4, Stage-3, Stage-5
Stage-4
Stage-0 depends on stages: Stage-4, Stage-3, Stage-6
Stage-2 depends on stages: Stage-0
Stage-3
Stage-5
Stage-6 depends on stages: Stage-5
STAGE PLANS:
Stage: Stage-1
Map Reduce
Map Operator Tree:
TableScan
alias: public_oi_fact_partition
Statistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONE
Select Operator
expressions: order_datekey (type: int), oiid (type: bigint), custom_order_id (type: bigint), ciid (type: int), bi_name (type: string), siid (type: int), si_name (type: string), classify (type: string), status (type: int), status_text (type: string), class1_id (type: int), class1_name (type: string), class2_id (type: int), class2_name (type: string), city_id (type: int), city_name (type: string), operate_area (type: int), company_id (type: int), standard_item_num (type: int), package_num (type: double), expect_num (type: decimal(30,6)), price (type: decimal(30,6)), order_weight (type: decimal(30,6)), order_amount (type: decimal(30,6)), order_money (type: decimal(30,6)), ci_weight (type: decimal(30,6)), c_t (type: string), u_t (type: string), real_num (type: decimal(30,6)), real_weight (type: decimal(30,6)), real_money (type: decimal(30,6)), cost_price (type: decimal(30,6)), cost_money (type: decimal(30,6)), price_unit (type: string), order_money_coupon (type: decimal(30,6)), real_money_coupon (type: decimal(30,6)), real_price (type: decimal(30,6)), f_activity (type: int), activity_type (type: tinyint), is_activity (type: tinyint), original_price (type: decimal(30,6)), car_group_id (type: bigint), driver_id (type: string), expect_pay_way (type: int), desc (type: string), coupon_score_amount (type: decimal(30,6)), sale_area_id (type: int), delivery_area_id (type: int), tag (type: int), promote_tag_id (type: bigint), promote_tag_name (type: string), pop_id (type: bigint), delivery_datekey (type: string)
outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13, _col14, _col15, _col16, _col17, _col18, _col19, _col20, _col21, _col22, _col23, _col24, _col25, _col26, _col27, _col28, _col29, _col30, _col31, _col32, _col33, _col34, _col35, _col36, _col37, _col38, _col39, _col40, _col41, _col42, _col43, _col44, _col45, _col46, _col47, _col48, _col49, _col50, _col51, _col52
Statistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONE
File Output Operator
compressed: false
Statistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONE
table:
input format: org.apache.hadoop.mapred.TextInputFormat
output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
name: public.public_t_par
Stage: Stage-7
Conditional Operator
Stage: Stage-4
Move Operator
files:
hdfs directory: true
destination: hdfs://ns1/user/hive/warehouse/public.db/public_t_par/.hive-staging_hive_2018-06-08_15-41-18_222_4176438830382881060-1/-ext-10000
Stage: Stage-0
Move Operator
tables:
partition:
delivery_datekey
replace: true
table:
input format: org.apache.hadoop.mapred.TextInputFormat
output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
name: public.public_t_par
Stage: Stage-2
Stats-Aggr Operator
Stage: Stage-3
Map Reduce
Map Operator Tree:
TableScan
File Output Operator
compressed: false
table:
input format: org.apache.hadoop.mapred.TextInputFormat
output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
name: public.public_t_par
Stage: Stage-5
Map Reduce
Map Operator Tree:
TableScan
File Output Operator
compressed: false
table:
input format: org.apache.hadoop.mapred.TextInputFormat
output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
name: public.public_t_par
Stage: Stage-6
Move Operator
files:
hdfs directory: true
destination: hdfs://ns1/user/hive/warehouse/public.db/public_t_par/.hive-staging_hive_2018-06-08_15-41-18_222_4176438830382881060-1/-ext-10000
uploading-image-422377.png
uploading-image-83430.png
目录都完成后_tmp.-ext-1000会变成-ext-1000 并参见stage-6
hive 动态分区实现 (hive-1.1.0)的更多相关文章
- Hive动态分区和分桶(八)
Hive动态分区和分桶 1.Hive动态分区 1.hive的动态分区介绍 hive的静态分区需要用户在插入数据的时候必须手动指定hive的分区字段值,但是这样的话会导致用户的操作复杂度提高,而且在 ...
- 什么是hive的静态分区和动态分区,它们又有什么区别呢?hive动态分区详解
面试官问我,什么是hive的静态分区和动态分区,这题我会呀. 简述 分区是hive存放数据的一种方式,将列值作为目录来存放数据,就是一个分区,可以有多列. 这样查询时使用分区列进行过滤,只需根据列值直 ...
- hive 动态分区
非常重要的动态分区属性: hive.exec.dynamic.partition 是否启动动态分区.false(不开启) true(开启)默认是 false hive.exec.dynamic.pa ...
- Hive动态分区详解
目录 动态分区调整 注意 动态分区插入 动静分区结合 例子 动态分区调整 动态分区属性:设置为true表示开启动态分区功能(默认为false)hive.exec.dynamic.partition=t ...
- hive动态分区和混合分区
各位看官,今天我们来讨论下再Hive中的动态分区和混合分区方面的一些知识点以及相关的一些问题. 前面我们已经讲过管理表和外部表的一般分区的一些知识点,对于需要对表创建很多的分区,那么用户就需要些很多的 ...
- shell脚本中向hive动态分区插入数据
在hive上建表与普通分区表创建方法一样: CREATE TABLE `dwa_m_user_association_circle`( `device_number` string, `oppo_nu ...
- Hive动态分区
1.开启支持动态分区 set hive.exec.dynamic.partition=true; --默认为false set hive.exec.dynamic.partition.mode=nos ...
- hive 动态分区与混合分区
hive的分区概念,相信大家都非常了解了.通过将数据放在hdfs不同的文件目录下,查表时,只扫描对应分区下的数据,避免了全表扫描. 提升了查询效率. 关于hive分区,我们还会用到多级分区.动态分区. ...
- Hive动态分区 参数配置及语法
Hive本身是不支持动态分区的.. 但动态分区是真的方便啊..不然手动维护要累死..按日期甚至小时来分区时动辄就好几千上万的分区..手动到哪一年去..? 想要用动态分区要先做一些设置来修改默认的配置. ...
随机推荐
- SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
Spring-servlet.xml <context:component-scan base-package="com.spring.mvc.controller"/> ...
- 【Nginx】之安装使用和配置SSL支持
本文采用的是nginx源码安装 1.下载nginx源码包 wget http://nginx.org/download/nginx-1.8.0.tar 或者登录nginx官网下载更高版本 2.ngin ...
- 流媒体技术笔记(DarwinStreamingServer相关)
简介 Darwin Streaming Server简称DSS.DSS是Apple公司提供的开源实时流媒体播放服务器程序.整个程序使用C++编写,在设计上遵循高性能,简单,模块化等程序设计原则,务求做 ...
- 廖雪峰Java4反射与泛型-3范型-3编写泛型
编写泛型类比普通的类要麻烦,而且很少编写泛型类. 1.编写一个泛型类: 按照某种类型(例如String)编写类 标记所有的特定类型例如String 把特定类型替换为T,并申明 Pair.java pa ...
- 1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- ueditor 正在读取目录及网络链接错误
环境 ueditor1_3_5-gbk-net .NET版本3.5 如果把项目直接改成4.0不会出现这样的问题,查看 问题1:正在读取目录 找到ueditor/ueditor.config.js 找 ...
- [UE4]子控件Child Widget顶层容器选择
如果父级容器是Canvas,则可以直接设置尺寸.放到其他widget的时候也会保持设定好的尺寸(而不管父容器是什么类型).
- 屏蔽windows快捷键的方法
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...
- CS229 6.16 Neurons Networks linear decoders and its implements
Sparse AutoEncoder是一个三层结构的网络,分别为输入输出与隐层,前边自编码器的描述可知,神经网络中的神经元都采用相同的激励函数,Linear Decoders 修改了自编码器的定义,对 ...
- 配置MySQL GTID(Global Transaction IDs)复制
一.GTID的简介 1.GTID的概述 .全局事物标识:global transaction identifieds. .GTID事物是全局唯一性的,且一个事务对应一个GTID. .一个GTID在一个 ...