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 stageStage-7 depends on stages: Stage-1 , consists of Stage-4, Stage-3, Stage-5Stage-4Stage-0 depends on stages: Stage-4, Stage-3, Stage-6Stage-2 depends on stages: Stage-0Stage-3Stage-5Stage-6 depends on stages: Stage-5
STAGE PLANS:Stage: Stage-1Map ReduceMap Operator Tree:TableScanalias: public_oi_fact_partitionStatistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONESelect Operatorexpressions: 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, _col52Statistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONEFile Output Operatorcompressed: falseStatistics: Num rows: 110000 Data size: 35162211 Basic stats: COMPLETE Column stats: NONEtable:input format: org.apache.hadoop.mapred.TextInputFormatoutput format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormatserde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDename: public.public_t_parStage: Stage-7Conditional OperatorStage: Stage-4Move Operatorfiles:hdfs directory: truedestination: hdfs://ns1/user/hive/warehouse/public.db/public_t_par/.hive-staging_hive_2018-06-08_15-41-18_222_4176438830382881060-1/-ext-10000Stage: Stage-0Move Operatortables:partition:delivery_datekey replace: truetable:input format: org.apache.hadoop.mapred.TextInputFormatoutput format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormatserde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDename: public.public_t_parStage: Stage-2Stats-Aggr OperatorStage: Stage-3Map ReduceMap Operator Tree:TableScanFile Output Operatorcompressed: falsetable:input format: org.apache.hadoop.mapred.TextInputFormatoutput format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormatserde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDename: public.public_t_parStage: Stage-5Map ReduceMap Operator Tree:TableScanFile Output Operatorcompressed: falsetable:input format: org.apache.hadoop.mapred.TextInputFormatoutput format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormatserde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDename: public.public_t_parStage: Stage-6Move Operatorfiles:hdfs directory: truedestination: 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

posted on 2018-08-31 14:08 姜小嫌 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/jiangxiaoxian/p/9565500.html

hive 动态分区实现 (hive-1.1.0)相关推荐

  1. hive动态分区shell_Hive动态分区 参数配置及语法

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

  2. Hive动态分区和分桶

    Hive动态分区和分桶 1. Hive动态分区和分桶 1.Hive动态分区 1.hive的动态分区介绍 2.hive的动态分区配置 3.hive动态分区语法 2.Hive分桶 1.Hive分桶的介绍 ...

  3. hive动态分区shell_hive-shell批量操作分区文件

    使用hive表的过程中经常需要一些便捷操作: 一.hdfs文件批量写SUCCESS文件,一般来说hive表生成结束,会产生一个_SUCCESS文件判断数据是否正常刷新完成 但是如果是动态分区插入表进行 ...

  4. hive动态分区报错

    HIVE动态分区,由于动态分区个数过多,map端内存溢出,报错. containerID=container_e86_1608865192015_2953765_01_000002] is runni ...

  5. hive分区用2个字段有何限制_[特性]Hive动态分区功能使用

    [特性]Hive动态分区功能使用 2016-01-31 21:40 说明 Hive有两种分区,一种是静态分区,也就是普通的分区.另一种是动态分区.动态分区在数据导入时,会根据具体的字段值自行决定导入, ...

  6. Hive 动态分区入门

    什么是动态分区? 分区的值由数据来确定,而不是说load数据的时候自行制定 如何动态分区? 前提条件 -- 属性说明: hive.exec.dynamic.partition=true:是否支持动态分 ...

  7. Hive动态分区导致的Jobtracker Hang

    昨天下午有20多分钟Hadoop平台无法跑Hive,Jobtracker的页面也打不开,hadoop job –list也hang住没有响应,过了10分钟后恢复了,查看gc日志发现Jobtracker ...

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

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

  9. HIVE 动态分区与静态分区

    HIVE分区,实际上是通过一个路径来标识的,而不是在物理数据中.比如每天的数据,可能分区是pt=20121023这样,那么路径中它就会变成:/hdfs/path/pt=20121023/data_fi ...

最新文章

  1. MDK KEIL 烧录STM32下载错误:Flash Timeout.Reset the Target and try it again.解决办法(芯片解锁 解除读报护)
  2. li span 时间向右排版问题
  3. Mysql数据库小命令
  4. 【Kafka】Kafka Producer整体架构概述及源码分析
  5. 购物车单选全选,计算总价,出现个小问题,没找到.....
  6. 2014最不受欢迎10编程语言种
  7. amos调节变量怎么画_结构方程模型建模思路及Amos操作--调节变量效果确定(二)...
  8. 教你如何零基础备考公务员
  9. 清洁机器人--屏幕显示LCD方案之MCU SPI 接口驱动ST7789 LCD显示
  10. 计算机启动硬盘响,电脑开机时硬盘响个不停的原因及解决方法
  11. 网页上传大文件被限制,如何设置配置文件
  12. wlh机器人_恐怖谷理论:人类对仿真机器人的天生恐惧
  13. 分类中常见的类别不平衡问题解决方法
  14. ubuntu搭建Fabric环境
  15. LeetCode第四天--罗马数字转整数
  16. Mac端口5000被ControlCe占用问题解决方法
  17. SpringSecurity 使用
  18. 无盘服务器网线接法,无盘经验:解析网吧千兆网线的标准做法
  19. java程序员实习刚进入公司一般会安排做什么?
  20. Visual Components 4.5安装手册

热门文章

  1. Java中的Unsafe在安全领域的一些应用总结和复现
  2. 安装Microsoft Windows SDK 7.1时出现的错误(附解决办法)
  3. PyRun_SimpleString的无穷怨念
  4. C++调用Python函数
  5. vue-cli3.0修改浏览器中的小图标
  6. Taro+react开发(79):taro生命周期setstate异步
  7. [html] 写一个三栏布局,中间固定,两边自适应(平均)
  8. [html] 页面导入样式时,使用link和@import有什么区别?
  9. [vue] 怎么配置使vue2.0+支持TypeScript写法?
  10. 前端学习(2854):简单秒杀系统学习之settimeout