hive的使用03
1.hive中的四种排序
1.1 order by :对全局进行排序,只能有一个reduce
select * from hive.employee order by id;
1.2 sort by :对每一个reduce内部数据进行排序,全局结果集没有排序
set mapreduce.job.reduces=3;设置reduce的个数为3
insert overwrite local directory '/opt/data/employee_sort_by'
row format delimited fields terminated by '\t' collection items terminated by '\n'
select * from hive.employee sort by dept_id;
1.3 distribute by :对数据进行分区,结合sort by进行合并使用,类似于mapreduce中的mapreduce中的partition,必须在sort by 之前
insert overwrite local directory '/opt/data/employee_distribute_by'
row format delimited fields terminated by '\t' collection items terminated by '\n'
select * from hive.employee distribute by dept_id sort by id asc;
1.4 cluster by:当distribute by 和 sort by 的字段相同时,可以使用cluster by 代替
2.使用udf自定义函数
2.1 编写udf函数
继承extends UDF
编写evaluate 方法
2.2 导入自定义函数到hive函数库
方法一:
add jar /opt/data/jars/my_lower.jar;
create temporary function my_lower as "com.ibeifeng.hive.udf.LowerUdf";
方法二:
create function self_lower as 'com.ibeifeng.hive.udf.LowerUdf' using jar 'hdfs://life-hadoop.life.com:8020/user/yanglin/data/jars/my_lower.jar';
3.hiveserver2的使用
3.1 启动hiveserver2 bin/hiveserver2
3.2 使用beeline进行连接
!connect jdbc:hive2://life-hadoop.life.com:10000 yanglin life@one
4.数据压缩
4.1 map 输出结果的压缩
set mapreduce.map.output.compress =true
set mapreduce.map.output.compress.codec=org.apache.hadoop.io.compress.SnappyCodec
4.2 reduce 输出结果的压缩
set mapreduce.output.fileoutputformat.compress=true
set mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec
4.3 map 输入数据的压缩
以压缩格式的文件存储数据(例如:orc,parquet)
create table if not exists hive.employee_orc_snappy (id int,name string,job string,manager_id int,apply_date string,salary double,
reward double,dept_id int)
row format delimited fields terminated by '\t'
stored as orc tblproperties("orc.compress"="SNAPPY");
其中该表的数据存储格式为orc,文件压缩格式为snappy
5.hive调优
5.1 修改 hive.fetch.task.conversion参数,使尽可能少用mapreduce
<!--尽可能的少用mapreduce-->
<property>
<name>hive.fetch.task.conversion</name>
<value>more</value>
</property>
5.2 使用大表拆分为小表和子表
5.3 使用外部表分区表
5.4 对表的数据的存储格式使用orc和parquet,并使用snappy压缩
5.5 对sql进行优化
common join / shuffle join / reduce join : 连接发生在reduce task 阶段
使用于大表和大表之间,每个表中的数据都从文件中读取
map join : 连接发生在map task 阶段
使用于小表和大表之间,大表的数据从文件中读取,小表的数据通过distributedCache加载到内存中
注:可以通过设置 hive.auto.convert.join = true 让程序自动识别使用map join还是reduce join。
SMB join :sort-merge-bucket join 是对reduce join 的一种优化
在创建表时声明[CLUSTERED BY (col_name, col_name, ...) [SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS],且两个表的分区字段要一致。
set hive.auto.convert.sortmerge.join=true;
set hive.optimize.bucketmapjoin = true;
set hive.optimize.bucketmapjoin.sortedmerge = true;
5.6 设置job并行执行
set hive.exec.parallel = true
set hive.exec.parallel.thread.number = 8 建议10~20,一般不用超过20
5.7 设置jvm重用
set mapreduce.job.jvm.numtasks = 1 一般不用超过9
5.8 设置reduce的个数
set mapreduce.job.reduces = 1
5.9 设置推测执行
set hive.mapred.reduce.tasks.speculative.execution = true
set mapreduce.map.speculative = true
set mapreduce.reduce.speculative = true
5.10 设置map的个数
set hive.merge.size.per.task = 256000000
hive的使用03的更多相关文章
- Flume1.9.0的安装、部署、简单应用(含分布式、与Hadoop3.1.2、Hbase1.4.9的案例)
目录 目录 前言 什么是Flume? Flume的特点 Flume的可靠性 Flume的可恢复性 Flume的一些核心概念 Flume的官方网站在哪里? Flume在哪里下载以及如何安装? 设置环境变 ...
- CDH quick start VM 中运行wordcount例子
需要注意的事情: 1. 对于wordcount1.0 ,按照http://www.cloudera.com/content/cloudera/en/documentation/HadoopTutori ...
- Hive 笔记
DESCRIBE EXTENDED mydb.employees DESCRIBE EXTENDED mydb.employees DESCRIBE EXTENDED mydb.employees ...
- Hive函数大全
一.关系运算: 1. 等值比较: = 语法:A=B 操作类型:所有基本类型 描述: 如果表达式A与表达式B相等,则为TRUE:否则为FALSE 举例: hive> select 1 from l ...
- 【转】Hive 基础之:分区、桶、Sort Merge Bucket Join
Hive 已是目前业界最为通用.廉价的构建大数据时代数据仓库的解决方案了,虽然也有 Impala 等后起之秀,但目前从功能.稳定性等方面来说,Hive 的地位尚不可撼动. 其实这篇博文主要是想聊聊 S ...
- Hive时间操作[转]
时间字段格式化 from_unixtime(unix_timestamp(VisitTime),'yyyy-MM-dd') 日期函数UNIX时间戳转日期函数: from_unixtime语法: f ...
- hive修改 表/分区语句
参考 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTable% ...
- 调用javaAPI访问hive
jdbc远程连接hiveserver2 2016-04-26 15:59 本站整理 浏览(425) 在之前的学习和实践Hive中,使用的都是CLI或者hive –e的方式,该方式仅允许使用Hi ...
- Spark入门实战系列--5.Hive(上)--Hive介绍及部署
[注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .Hive介绍 1.1 Hive介绍 月开源的一个数据仓库框架,提供了类似于SQL语法的HQ ...
随机推荐
- Python开发【前端】:汇总
页面模板 1.EasyUI(推荐指数★) JQuery EasyUI中文网 下载 使用方法:把文件下载到本地.直接从官网上把源码拷贝过来,更改下js的路径即可 优点:功能非常多.非常齐全 偏做后台管理 ...
- asp.net 自带的缓存
本文导读:在.NET运用中经常用到缓存(Cache)对象.有HttpContext.Current.Cache以及HttpRuntime.Cache,HttpRuntime.Cache是应用程序级别的 ...
- input固定在底部
// input固定在底部//isFocusing获取焦点:true 失去焦点:false _onTouchInput(isFocusing){ this.phone_width = screen.w ...
- 搭建Python+Django开发环境
第一步:安装python. 常见的windows系统,直接python网站下载 最新的版本python3.5. python安装好之后,配置好环境变量.使得python和 pip命令能够正常使用. 第 ...
- Jenkins
http://www.cnblogs.com/chowmin/category/598634.html
- 限制action所接受的请求方式或请求参数
原文:http://www.cnblogs.com/liukemng/p/3726897.html 2.限制action所接受的请求方式(get或post): 之前我们在HelloWorldContr ...
- csuoj 1117: 网格中的三角形
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1117 1117: 网格中的三角形 Time Limit: 3 Sec Memory Limit: ...
- c语言的学习秘籍之链表
刚翻出来的作品,有点低级,但希望能起到作用: #include<stdio.h>#include<stdlib.h>#include<time.h>#include ...
- union和union all有什么不同?
union和union all有什么不同? 相同点:用来获取两个或者两个以上结果集的并集 不同点: union会自动去重,排序 union all没有去重,排序
- 一些CSS
/*自定义*白烟*文本/边框/背景色*/ .text-whitesmoke,a.text-whitesmoke:link,a.text-whitesmoke:visited,.button.borde ...