Hive commands notes

hive> insert overwrite directory '/result' select * from userbehavior;

hive> insert overwrite local directory '/hive_test/result' select * from userbehavior;

hive> create table userbehavior as select /*+mapjoin(r)*/ r.userid,m.movieid,m.title,r.rating from movie m join rate r on m.movieid=r.movieid limit 10;

hive> set hive.groupby.skewindata = true;

hive> set hive.enforce.bucketing = true;开启bucket功能

#create bucket

hive> create external table rating_table
(
userid int,
movieid string,
rating string
)
clustered by (userid) into 32 buckets;

hive> create external table rating_table
(
userid string,
movieid string,
rating string
)
partitioned by (dt string)
row format delimited fields terminated by '\t'
lines terminated by '\n';

#UDF

hive> add jar /hive_test/hive_udf.jar;
hive> create temporary function upper_func as 'test.Uppercase';
hive> select movieid, title, upper_func(title) from movie_table;

#UDTF

hive> add jar /hive_test/hive_udtf.jar;  
hive> create temporary function explode_func as 'test.Expolde';

create external table udtf_test_table
(data string
)
row format delimited fields terminated by '\t'
stored as textfile
location '/hive_test';

hive> select explode_func(data) from udtf_test_table;

#UDAF

add jar /hive_test/hive_udaf.jar;
create temporary function gen_ts_max as 'test.GenMaxRow';

create external table udaf_test_table
(id STRING,
ts STRING,
data STRING
)
row format delimited fields terminated by '\t'
stored as textfile
location '/hive_test';

select id, gen_ts_max(ts, data) from udaf_test_table group by id;

select id,mm.col0 as ts, mm.col1 as data
from(
select id, gen_ts_max(ts, data) as mm from udaf_test_table group by id
) s;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SeasonRun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值