hive jiqiao

1.在Hive中可以使用正则表达式
set hive.support.quoted.identifiers=None; 
select a.pin, `(pin)?+.+` from Table
1
2
2.输出表数据时,显示列名
set hive.cli.print.header=true;

3.排序优化
order by全局排序,一个reduce实现,不能并行故效率偏低;
sort by部分有序,配合distribute by使用;
cluster by col1 == distribute by col1 sort by col1,但不能指定排序规则;

4.join优化
多表join的key值统一则可以归为一个reduce;
先过滤后join;
小表在前读入内存,大表在后;
使用left semi join 代替in功能,效率更高;
小表join大表时数据倾斜优化:

select t1.a,t1.b from table t1 join table2 t2  on ( t1.a=t2.a)
select /*+ mapjoin(t1)*/ t1.a,t1.b from table t1 join table2 t2  on ( t1.a=t2.a)
1
2
5.分区插入
静态插入:需要指定插入的分区dt,name的值;

insert overwrite table test partition (dt='2018-10-17', name='a') 
select col1, col2 from data_table where dt='2018-10-17' and  name='a';
1
2
动态插入:可以自动从列中匹配分区;

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table test partition (dt, name) 
select col1, col2, dt, name from data_table where dt='2018-10-17';
1
2
3
4
6.抽样
---   随机排序后取前10个
select * from table1 distribute by rand() sort by rand() limit 10
select * from table1 order by rand() limit 10 --不可分布式,效率低
---   抽样函数
select * from table1 tablesample(50 PERCENT)
select * from table1 tablesample(1M)
select * from table1 tablesample(10 ROWS)
---   创建分桶表
create table bucketed_user(id int ,name string) 
clustered by (id)  sorted by (name)  --指定分桶列和排序列
into 4 buckets 
row format delimited fields terminated by '\t' stored as textfile;
---   向分桶表中插入数据
set hive.enforce.bucketing=true;(hive2.0好像没有这个参数)
insert overwrite rable bucketed_users select id,name from users ;
select * from bucketed_users tablesample(bucket 1 out of 2 on id);
#从1号bucket起抽取  2/总bucket个数  个bucket的数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
998.与presto的差异
presto具有严格的数据类型,在做比较时两侧类型必须严格相同,手动转换。

cast(a as bigint)>b
cast(6 as double)/4
6*1.0/4
1
2
3
时间函数的差异性

dt=cast(current_date+interval '-1' day as varchar)#昨天
dt=date_format(current_timestamp-interval '1' month, '%Y-%m-01')#上个月1日
dt=date_format(cast(date_format(current_timestamp , '%Y-%m-01') as date) - INTERVAL '1' DAY, '%Y-%m-%d') #上个月底
1
2
3
999.数据拆分行

--------------------- 
作者:LightsUpW 
来源:CSDN 
原文:https://blog.csdn.net/lightsupw/article/details/80916740 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

 

https://blog.csdn.net/lightsupw/article/details/80916740

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值