笔者使用的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)的更多相关文章

  1. Hive动态分区和分桶(八)

    Hive动态分区和分桶 1.Hive动态分区 1.hive的动态分区介绍 ​ hive的静态分区需要用户在插入数据的时候必须手动指定hive的分区字段值,但是这样的话会导致用户的操作复杂度提高,而且在 ...

  2. 什么是hive的静态分区和动态分区,它们又有什么区别呢?hive动态分区详解

    面试官问我,什么是hive的静态分区和动态分区,这题我会呀. 简述 分区是hive存放数据的一种方式,将列值作为目录来存放数据,就是一个分区,可以有多列. 这样查询时使用分区列进行过滤,只需根据列值直 ...

  3. hive 动态分区

    非常重要的动态分区属性: hive.exec.dynamic.partition  是否启动动态分区.false(不开启) true(开启)默认是 false hive.exec.dynamic.pa ...

  4. Hive动态分区详解

    目录 动态分区调整 注意 动态分区插入 动静分区结合 例子 动态分区调整 动态分区属性:设置为true表示开启动态分区功能(默认为false)hive.exec.dynamic.partition=t ...

  5. hive动态分区和混合分区

    各位看官,今天我们来讨论下再Hive中的动态分区和混合分区方面的一些知识点以及相关的一些问题. 前面我们已经讲过管理表和外部表的一般分区的一些知识点,对于需要对表创建很多的分区,那么用户就需要些很多的 ...

  6. shell脚本中向hive动态分区插入数据

    在hive上建表与普通分区表创建方法一样: CREATE TABLE `dwa_m_user_association_circle`( `device_number` string, `oppo_nu ...

  7. Hive动态分区

    1.开启支持动态分区 set hive.exec.dynamic.partition=true; --默认为false set hive.exec.dynamic.partition.mode=nos ...

  8. hive 动态分区与混合分区

    hive的分区概念,相信大家都非常了解了.通过将数据放在hdfs不同的文件目录下,查表时,只扫描对应分区下的数据,避免了全表扫描. 提升了查询效率. 关于hive分区,我们还会用到多级分区.动态分区. ...

  9. Hive动态分区 参数配置及语法

    Hive本身是不支持动态分区的.. 但动态分区是真的方便啊..不然手动维护要累死..按日期甚至小时来分区时动辄就好几千上万的分区..手动到哪一年去..? 想要用动态分区要先做一些设置来修改默认的配置. ...

随机推荐

  1. HTML5 Canvas水波纹动画特效

    HTML5的Canvas特性非常实用,我们不仅可以在Canvas画布上绘制各种图形,也可以制作绚丽的动画,比如这次介绍的水波纹动画特效.以前我们也分享过一款基于HTML5 WebGL的水波荡漾动画,让 ...

  2. Java面向对象课程设计——购物车

    Java面向对象课程设计——购物车 小组成员:余景胜.刘格铭.陈国雄.达瓦次仁 一.前期调查 流程 客人(Buyer)先在商城(Mall)中浏览商品(Commidity),将浏览的商品加入购物车(Sh ...

  3. a:hover应用精粹

    原本想把题目叫做“纯CSS相册2”的,但在实现过程中试验了许多东西,干脆全部写出来分享了.大家知道,能兼容IE6的具有动态切换能力的CSS属性也只有hover伪类了,但hover伪类在IE仅对链接生效 ...

  4. nginx - 性能优化,突破十万并发

    一般来说nginx配置文件中对优化比较有作用的为以下几项: worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_affinity ...

  5. 工具类System,Runtime,Math,Date,Calendar

    API--- java.lang.System: 属性和行为都是静态的. long currentTimeMillis(); // 返回当前时间毫秒值   exit();  // 退出虚拟机 Prop ...

  6. 百度地图api公交路线,IE下跳转百度地图后中文变成乱码的解决办法

    百度开放的公交路线的链接,IE跳转会出现中文变成乱码的问题.如图: //创建InfoWindow function createInfoWindow() { var desDiv = []; desD ...

  7. jQuery的杂项

    <script  src="引入插件"></script> 位置应写在head中,在http协议中,当你浏览网页时,会先加载head里面的东西  刷新页面时 ...

  8. 逻辑运算符&逻辑短路

    (1)and 逻辑与 全真则真,一假则假 print(True and True) #True print(False and True) #False print(False and False) ...

  9. CRM 2016 刷新 Iframe

    在CRM中刷新IFame: /// <summary>刷新Iframe的内容,用于表单上刷新iframe里的内容</summary> var iframe = Xrm.Page ...

  10. 理解HDFS高可用性架构

    在Hadoop1.x版本的时候,Namenode存在着单点失效的问题.如果namenode失效了,那么所有的基于HDFS的客户端——包括MapReduce作业均无法读,写或列文件,因为namenode ...