hive 动态分区实现 (hive-1.1.0)

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/413417.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

浏览器的组成

外壳shell:User Interface(用户界面)、Browser engine(浏览器引擎)、Networking(网络)、UI Backend(UI 后端)、Date Persistence(数据持久化存储)…

[css] css的加载会阻塞js运行吗?为什么?

[css] css的加载会阻塞js运行吗?为什么? 会阻塞js的执行,因为js可能会去获取或改变元素的样式,所以浏览为了不重复渲染, 等所有的css加载渲染完成后在执行js个人简介 我是歌谣,欢迎和大家一起交流前后端知…

JS基础知识点总结

NaN 与任何值相比较 都是false (包括它自己 如NaN NaN >false),可以理解为它连自己的不认识parseInt("123abc") 计算机是从头到尾读字符串,如果不是数字就截断,直接返回parseFloat同理num 123.1456789 num.toFixed(3…

[css] css的加载会阻塞DOM树解析和渲染吗?为什么

[css] css的加载会阻塞DOM树解析和渲染吗?为什么 css的加载不会阻止DOM树的解析 css的加载会阻止DOM树的渲染,因为css的下载完成后解析成CSSOM与DOM生成渲染树后,页面才会渲染,绘制出来个人简介 我是歌谣,欢迎和大家…

0901

下拉刷新一万赞:https://github.com/scwang90/SmartRefreshLayout git上搜索:refreshLayouthttps://github.com/search?odesc&qrefreshLayout&sstars&typeRepositories SwipeRefreshLayout pullRefresh XRecyclerView转载于:https://www.cn…

jQuery Validate 前端校验

参考自:https://www.runoob.com/jquery/jquery-plugin-validate.html 建议:将引入的js,jQuery,css文件下载到自己的本地或者远程服务器 否则:如果您的网站使用了SSL证书请求的安全策略,注意引用的文件是否…

[css] 异步加载CSS的方式有哪些?

[css] 异步加载CSS的方式有哪些? 异步加载CSS 说到加载 CSS 这种事儿不是很简单吗?像这样咯: 这不就完事儿了嘛! 这样是没错!但是这样有问题啊——会阻塞渲染!浏览器看到这个标签就会停下手里的活儿&…

Golang 垃圾回收机制

1. Golang GC 发展 Golang 从第一个版本以来,GC 一直是大家诟病最多的。但是每一个版本的发布基本都伴随着 GC 的改进。下面列出一些比较重要的改动。 v1.1 STWv1.3 Mark STW, Sweep 并行v1.5 三色标记法v1.8 hybrid write barrier2. GC 算法简介  这一小节介绍三…

Bootstrap FileInput(文件上传)中文API整理

下载地址、API和DOM地址(英语好的小伙伴可以看看) 下载地址:https://github.com/kartik-v/bootstrap-fileinput API文档 :http://plugins.krajee.com/file-input D E M O:http://plugins.krajee.com/file-input/demo …

[css] 举例说明如何从html元素继承box-sizing?

[css] 举例说明如何从html元素继承box-sizing? html{box-sizing:border-box;}*,*:before,*:after{box-sizing:inherit;}个人简介 我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易, 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起…

Configutation读取properties文件信息

commons configuration可以很方便的访问配置文件和xml文件中的的内容。Commons Configuration 是为了提供对属性文件、XML文件、JNDI资源、来自JDBC Datasource数据的访问。 官方文档:http://commons.apache.org/proper/commons-configuration/ 我们研究configurati…

JavaScript 所有数据类型

JavaScript 所有数据类型 在 JavaScript 中有 5 种不同的数据类型: stringnumberbooleanobjectfunction 3 种对象类型: ObjectDateArray 2 个不包含任何值的数据类型: nullundefined 可以使用 typeof 操作符来查看 JavaScript 变量的数据…

[css] 使用css的attr()写一个类似a标签title的提示框

[css] 使用css的attr()写一个类似a标签title的提示框 .box{position:relative;}.box:hover{content: attr(data-title); display: inline-block;padding: 10px 14px;border: 1px solid #ddd;border-radius: 5px;position: absolute;top: -50px;left: -10px;}个人简介 我是歌…

JavaScript 严格模式(use strict)

使用 "use strict" 指令 "use strict" 指令在 JavaScript 1.8.5 (ECMAScript5) 中新增。 它不是一条语句,但是是一个字面量表达式,在 JavaScript 旧版本中会被忽略。 "use strict" 的目的是指定代码在严格条件下执行。…

IO 概括

# 一、概览 Java 的 I/O 大概可以分成以下几类: - 磁盘操作:File- 字节操作:InputStream 和 OutputStream- 字符操作:Reader 和 Writer- 对象操作:Serializable- 网络操作:Socket- 新的输入/输出&#xff1…

JavaScript this 关键字

面向对象语言中 this 表示当前对象的一个引用。 但在 JavaScript 中 this 不是固定不变的,它会随着执行环境的改变而改变。 在方法中,this 表示该方法所属的对象。如果单独使用,this 表示全局对象。在函数中,this 表示全局对象。…

[css] 鼠标事件css的:hover和js的mouseover有什么区别?

[css] 鼠标事件css的:hover和js的mouseover有什么区别? JavaScript中鼠标事件有:onmouseover和onmouseout: 当鼠标移入和移出时触发事件onmousedown和onmouseup: 当鼠标按钮被按下或者松开时触发事件onclick和ondbclick &#xf…

【一步一步学习spring】spring入门

1. spring概述 spring是一个开源框架spring为简化企业级应用开发而生,解决的是业务逻辑层和其他各层的松耦合问题,他将面向接口的编程思想贯穿整个系统应用。spring是javaSE/EE的一站式框架。web层有spring-mvc,业务层有spring ioc、事务等机…

JavaScript 操作 HTML DOM (文档对象模型) 相关知识点

HTML DOM 树 通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML。 JavaScript 能够改变页面中的所有 HTML 元素JavaScript 能够改变页面中的所有 HTML 属性JavaScript 能够改变页面中的所有 CSS 样式JavaScript 能够对页面中的所有事件做出反应…

[css] 举例说明你对指针事件(pointer-events)的理解

[css] 举例说明你对指针事件(pointer-events)的理解 pointer-events CSS 属性指定在什么情况下 (如果有) 某个特定的图形元素可以成为鼠标事件的 target。 当point-events 为none时,比如a连接不再生效个人简介 我是歌谣,欢迎和大…