HiveSql(1)mapjoin、分区表
2016-01-08 17:10
357 查看
mapjoin、分区表、不等值匹配
业务需求:
A表,小表,穷举的100个动漫电影的IP,表结构ip(id string, key string)
B表,大表,每天的交易数据,上亿条,表结构order(ds string, item_titlestring,buyer_id string, fee string)
现在想要得到这100个动漫电影相关产品的每天的销售额、购买人数。
SQL:
1、建表
create table if not exists jieguo
(
ds string,
fee string ,
cnt string
)
partitioned by (pt string )
2、跑数据
Insert overwrite table jieguo partition (pt=201503)
Select /*+MAPJOIN(a)*/
b.ds,sum(b.fee),count(b.buyer_id)
from ip b
Join
(Select ds, fee,buyer_id
From order
Where ds>=20150101 and ds<=20150331
)b
On instr(b.item_title,a.key)>0
Group by b.ds
学习要点:
1、/*+MAPJOIN*/的用法
如果关联的2张表大小差距悬殊或者进行不等值连接时,一般的join会导致运行速度很慢,使用mapjoin可以有效提高效率
使用场景:
(1)关联操作中的一张表非常小
(2)不等值连接
Select /*+MAPJOIN(a)*/,括号里加的是小表的名称
2、分区表
如果输出的数据比较多,可以采取分区的形式
建表时加一条语句partitioned by
跑数据时Insert overwrite table jieguo partition (pt=201503)
业务需求:
A表,小表,穷举的100个动漫电影的IP,表结构ip(id string, key string)
B表,大表,每天的交易数据,上亿条,表结构order(ds string, item_titlestring,buyer_id string, fee string)
现在想要得到这100个动漫电影相关产品的每天的销售额、购买人数。
SQL:
1、建表
create table if not exists jieguo
(
ds string,
fee string ,
cnt string
)
partitioned by (pt string )
2、跑数据
Insert overwrite table jieguo partition (pt=201503)
Select /*+MAPJOIN(a)*/
b.ds,sum(b.fee),count(b.buyer_id)
from ip b
Join
(Select ds, fee,buyer_id
From order
Where ds>=20150101 and ds<=20150331
)b
On instr(b.item_title,a.key)>0
Group by b.ds
学习要点:
1、/*+MAPJOIN*/的用法
如果关联的2张表大小差距悬殊或者进行不等值连接时,一般的join会导致运行速度很慢,使用mapjoin可以有效提高效率
使用场景:
(1)关联操作中的一张表非常小
(2)不等值连接
Select /*+MAPJOIN(a)*/,括号里加的是小表的名称
2、分区表
如果输出的数据比较多,可以采取分区的形式
建表时加一条语句partitioned by
跑数据时Insert overwrite table jieguo partition (pt=201503)
相关文章推荐
- 用Jedis操作redis示例一,Key,value HashMap
- Azure MySQL PaaS (2) MySQL PaaS修改时区
- redis+crontab异步处理任务
- 15-oracle中的selectKey和sysdate
- Oracle10g忘记sys、system密码找回及scott登陆问题
- Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc version 11.0.0.0
- python etl oracle导出 2
- Oracle 小记
- Hibernate的FlushMode与session.flush()
- MSSQL Server Replication机制主从同步实践
- Oracle APEX 5.0 新手教程(七) URL格式说明
- 时间to_date,层级查询 --工作备忘2016/1/8
- 安装php-redis扩展
- mysql 性能优化方案
- MySQL函数
- Html5 web sql database
- Redis配置详解
- Oracle 11g 创建临时window时间窗口 收集统计信息
- Oracle管理拾遗(长期更新)
- mysql性能的检查和调优方法