Hive函数笔记--常用函数解析

2018-08-31  本文已影响146人  风筝flying

前言

本文不定期更新,记录工作中接触使用过的Hive函数

常用函数

select get_json_object(pricecount,'$.buyoutRoomRequest') new_id,pricecount
  from table_sample a
 where d='2018-08-31' limit 100
select m.*,n.pricecount
  from (select 
              from table_sample a 
            where d='2018-08-31' limit 100)n
  lateral view json_tuple(pricecount,'paymentType','complete') m as f1,f2
select split('123,3455,2568',',')
select split('sfas:sdfs:sf',':')
select explode(split('123,3455,2568',','))
select j.nf,p.* from (
select m.*,n.pricecount
  from (select * from ods_htl_htlinfogoverndb.buyout_appraise a where d = '${zdt.format("yyyy-MM-dd")}' limit 100)n
 lateral view json_tuple(pricecount,'paymentType','complete') m as f1,f2 )p
 lateral view explode(split(regexp_replace(p.f1,'\\[|\\]',''),',')) j as nf

该函数第一个参数接收int/bigint类型的10位时间戳变量,带毫秒的13位时间戳需要做截取,第二个参数是返回的日期的格式,可以不设置,默认是格式:yyyy-MM-dd HH:mm:ss

select from_unixtime(1000000000);
select from_unixtime(1000000000,'yyyy-MM-dd HH');
select unix_timestamp();
select unix_timestamp('2018-09-05 10:24:36');
select unix_timestamp('2018-09-05 10','yyyy-MM-dd HH');
select str_to_map('abc:11&bcd:22', '&', ':')
with t as (
select 1 id,123 value
  union all
select 1 id,234 value
  union all
select 2 id,124 value
)
select t.id,collect_set(t.value)
  from t
 group by t.id
with t as (
select 1 id,123 value
  union all
select 1 id,234 value
  union all
select 2 id,124 value
  union all
select 2 id,124 value
)
select t.id,collect_set(t.value),collect_list(t.value)
  from t
 group by t.id
select array_contains(array(1,2,3,4,5),3)
true
上一篇 下一篇

猜你喜欢

热点阅读