hive的基础知识以及参数调优

hive的基础知识

数据类型

基本数据类型

数据类型长度
tinyint1byte
smalint2byte
int4byte
bigint8byte
booleantrue 或者 false
float单精度浮点型
double双精度浮点型
string字符序列 用单引号或者双引号
timestamp整数,浮点数,字符串
binary字节数组

集合数据类型

数据类型描述
structstruct(first string,last string)第一个元素可以用.first来引用
map相当于Java的map 可以用key来引用值 map(‘first’,’xx’,’last’, ‘zz’)第一个值可以用map[‘first’]引用
array相当于Java的数组 array(‘xx’,’zz’) xx可以用array[0]引用

优点:提供更高吞吐量的数据,减少‘头部寻址’的次数
缺点:破坏标准格式,带来数据冗余

文本文件的数据编码

hive中默认的记录和字段分隔符

分隔符描述
\n换行符 默认行与行之间的分割,也只有这种
^Acreate table 用8进制的\001表示
^Bcreate table 用8进制的\002表示,用于分割array和struct的元素,map键值对
^Ccreate table 用8进制的\003表示,用于分割map键和值

排序

保留字描述
order by全局排序
sort by局部排序
distribute by控制map的输出在reduce怎样划分
cluster by=distribute by t.id sort by t.id

hive参数调优

一、压缩

启动压缩 有返回压缩的格式就是启动
set io.compression.codecs;
中间压缩(中间数据值上个mapreduce作业的输出)
set hive.exec.compress.intermediate=true;
set hive.intermediate.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
set hive.intermediate.compression.type=BLOCK;
结果输出进行压缩
set hive.exec.compress.output=true;
set mapreduce.output.fileoutputformat.compress=true;
set mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
set mapreduce.output.fileoutputformat.compress.type=BLOCK;

文件格式容量压缩情况备注
TEXT585数据有参数化的分隔符号,用textfile
RCFILE50514%执行数据分析,并高效的存储数据,用rcfile
Parquet22162%数据所在的文件的块尺寸小,用sequencefile
ORCFile13178%支持事务,并且希望减少数据的存储空间,提高性能,用orcfile

二、连接

// (1) 自动连接 当连接一个大表和小表,自动将小表缓存到本地,在map的阶段与大表进行连接,其次避免了hive查询中的倾斜连接
set hive.auto.conver.join=true;
set hive.auto.conver.join.noconditionaltask=true;
set hive.auto.conver.join.noconditionaltask.size=10000000;
set hive.auto.conver.join.use.nonstaged=true;
// (2) 倾斜连接 两个大表进行连接,会先基于连接键进行排序,然后mapper将特点键值的所有行发给同一个reducer。
set hive.optimize.skewjoin=true;//是否在连接之后的倾斜创建独立的执行计划
set hive.skewjoin.key=100000;//
set hive.skewjoin.mapjoin.map.tasks=10000;//指定map连接的作业数,可控制粒度一起使用
set hive.skewjoin.mapjoin.min.split=33554432;//控制粒度
// (3)桶连接
set hive.optimize.bucktmapjoin=true; // 是否尝试桶map连接
set hive.optimize.bucktmapjoin.sortedmerge=true; //是否尝试在map连接中使用归并排序

三、优化limit操作

//默认的limit仍然会查询整个查询,然后再返回限定的行数
set hive.limit.optimize.enable=true;
set hive.limit.row.max.size=100000;
set hive.limit.optimize.limit.file=10;
set hive.limit.optimize.fetch.max=50000;

四、启动并发执行

set hive.exec.parallel=true;
set hive.exec.parallel.thread.number=8;

五、使用单一reduce执行多个group by

set hive.multigroupby.singlereducer=true;

六、控制并行的reduce任务数

set hive.exec.reducers.bytes.per.reducer=256000000;
set hive.exec.reducers.max=1009

欢迎拍砖指正,共同进步^_^

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值