1.hive的集中join方式和使用场景,map-side join的reduce-side join适用场景
2.复杂查询的单标过滤条件使用位置,where和on的区别,涉及列裁剪,分区裁剪;
列裁剪优化:
select * from order_table limit 10;优化后只读取需要的数据列
select user,item from order_table limit 10;
分区裁剪优化使用查询条件添加分区:
select count(orderid) form order_table where[i] dt='2014-11-11' [/i]and to_data(sale_time)='2014-11-11' and hour(to_date(sale_time))=10
判断扫描的分区有个explain dependency帮助语法可以看出扫描的分区,帮助优化hiveql
如果join的key相同优化减少JOB数:
select a.val,b.val,c.val from a join b on (a.key = b.key1) join c on [i](b.key1=c.key)[/i];// 不要使用c.key = b.key2
muti-insuert,union all使用
muti-insert使用
insert overwrite table tmp1 select ... from a where 条件1
insert overwrite table tmp1 select ... from a where 条件1
//优化后
from a
insert overwrite table tmp1 select ... where 条件1
insert overwrite table tmp1 select ... where 条件2;
避免笛卡尔积:
select ...
from order_table ot
left outer join(
selct * from order_table_info oti
where (oti.mobile <> 'unkenwun' or oti.imsi <> 'unkenown')
and oti.imei<> 'unknuwn'
and oti.pt='$data_desc'
) a
on ot.app_id=a.app_id and oti.imei=a.imei
//提桥过滤,使用on作为条件
join前过滤掉不需要的数据:
//以下应该先进行过滤分区,再执行子查询
select a.val,b.val from a.left outer join b on (a.key=b.key)where a.ds='2009-07-07' and b.ds =''2009-07-07
//优化后
select x.val,b.val from (select key,val from a where a.ds='2009-07-07') x left outer join (select key,val from b where b.ds = '2009-07-07') y
on x.key=y.key
3.distribute by/sort by/cluster by/order by语法的使用和区别
//distinct 和 group by 尽量避免使用distinct,用group by代替
select distinct key from table
select key from table group by key
//order by优化
1.order by在全局有序,所以要排序是在一个reduce中实现,不能并发执行。
2.sort by部分实现排序,单个reduce输出的结果是有序的,效率高,通常和distribute by关键字一起使用
3.cluster by col 等价于distribute by col sort by col1 但是不能分配排序的规则和权重
4.hive函数使用:
(京东自己开发sysdate()),date_format(),concat,substr,like,split,explode 等
select col1,col2,newCol from table lateral view explode(myCol) adTanle as newCol
//使用explode进行转换,按照不同维度进行订单汇总
select type,code,sum(sales) from(
select split(part,'_')[1] as type,
split(part,'_')[0] as code,
sales from order_table LATERRAL VIEW explode(split(concant(province,'_1-',city,'_2-',country,'_3-')))
adTable AS part
)df group by type,code;
5.union all注意事项
union all在不同表相当于是multiple inputs,同一个表下相当于map一次输出多条
hive对union all的查询只限于非嵌套查询
select * from (
select c1,c2,c3 from t1 group by c1,c2,c3
union all
select c1,c2,c3 from t2 group by c1,c2,c3)
t3;
//如果t1和t2比较小的话使用下边的写法
select * from
(select * from t1
union all
select * from t2
)t3
group bu c1,c2,c3;
不同表太多的union all操作可以使用创建临时分区
insert overwrite table test (flag='1')
select sndaid,mobile from test1
insert overwrite table test (flag='2')
select sndaid,mobile from test2
6.数据倾斜的原因和解决方式
//数据倾斜
任务长时间维持在99%,查看任务页面发现只有少量的reduce子任务未完成,因为此处的reduce和其他的reduce差异过大,单一的reduce的记录数与平均数差异过大
[size=x-large]7.hive分区表(EDW常见的几种分区表)更有效的查询方法[/size]
8.多表插入
9.hive NULL值关联:
10.动态分区:
//设置参数
set hive.exec.dyanmic.partition=true
set hive.exec.dyanmic.partition.mode=nonstrict
//创建动态分区表
create table test(
sndaid string,
mobile string,
)partitioned by (dt string)
stored an rcfile;
//插入动态分区数据
insert overwrite table test partition(dt)
select sndaid,mobile.dt feom test2
11.数据采样:
分享到:
相关推荐
《Hive数据仓库案例教程》教学课件 第5章 Hive数据操作.pdf《Hive数据仓库案例教程》教学课件 第5章 Hive数据操作.pdf《Hive数据仓库案例教程》教学课件 第5章 Hive数据操作.pdf《Hive数据仓库案例教程》教学课件 第...
Hive是基于Hadoop的大数据仓库管理系统,提供了类SQL的数据操作语言DML,用于操作数据表中的数据,例如数据的加载、查询和插入等操作。下面是Hive数据操作语言的详细讲解: 加载文件 加载文件是Hive中常见的数据...
抽样查询是 Hive 数据查询语言中的一种重要操作,用于从大规模数据集中随机抽样数据。常用的抽样查询函数包括: * TABLESAMPLE:从大规模数据集中随机抽样数据 * RAND:生成随机数 Hive 数据查询语言是用于从...
Hive简介:...Hive数据类型: https://blog.csdn.net/weixin_45102492/article/details/91048019 Hive之DDL数据定义: https://blog.csdn.net/weixin_45102492/article/details/91349323 Hive
《Hive数据仓库案例教程》教学大纲.pdf《Hive数据仓库案例教程》教学大纲.pdf《Hive数据仓库案例教程》教学大纲.pdf《Hive数据仓库案例教程》教学大纲.pdf《Hive数据仓库案例教程》教学大纲.pdf《Hive数据仓库案例...
hive 基本操作的命令和hive 实用命令等,有利与学习hive和mysql
本文档将详细讲解 Hive 的数据定义语言(DDL),包括数据库的基本操作、数据表的基本操作、分区表、分桶表、临时表、视图、索引等内容。 数据库的基本操作 Hive 中创建数据库的语法格式如下: CREATE (DATABASE|...
(3)sqoop数据迁移,完成HIve与MySQL数据库中的数据交互 (4)Echarts搭建动态可视化大屏 (5)SpringBoot搭建可视化后台系统,完成前端与后台的数据传递与交互。 (6)基于Cenots7 搭建虚拟机,配置Hadoop、HDFS、...
林子雨Hive数据集下载
此篇文章主要选取关键性指标,数据校验数据源Hive和目标ES内的数据是否一致; 因为你不知道将Hive的数据导入到了ElasticSearch后,数据量是否准确,所以需要钉钉报警校验ElasticSearch和Hive数据仓库内的数据质量,...
Hive常用DML操作,基础篇
实现elasticsearch与hive数据互通 环境 实验性单节点集群 vagrant.linux16.4.4(无doctor) hive2.3.3+beeline es6.2.2 kibana6.2.2 elasticsearch-hadoop-6.2.2.jar 没有doctor
使用javaJDBC连接hive数据,实现简单的操作!
hive的定义与简单操作,大数据开发hive的简单介绍,入门级别知识点.
第3章 HiveSQL 数据操控、查询语言(DML、DQL)DML-Load加载数据背景回想一下,当在Hive中创建好表之后,默认就会在HDFS上创建一个与之对
附件包括一个数据文件(csv文件,包括92168条记录)和一个包含操作命令的txt文件,用于Hive的学习。 其中csv文件可以上传到HDFS构建测试数据,txt文件给出了相关的操作命令。
hive数据加载的几种方式、数据的导出、数据简单查询
Hive数据操作-教案.pdf 学习资料 复习资料 教学资源
第7讲Hive数据仓库.pptx
hive数据存储模式,对理解hive有帮助