♥♥♥1.if(condition,true_val,false_val) 双重分支,相当于三元运算符
♥♥2.case field when v1 then s1 when v2 then s2 else sn end 等值判断多分支
case when field>=v1 then s1 ...else sn send 区间判断多分枝
♥♥3.nvl(field,default_val) field==null?default_val:field
4.coalesce(T...vs) 返回参数列表中第一个非空值
5.isnull(field) 返回field列表是否为空
6.isnotnull(field)返回field列表是否不为空
注意窗口函数不支持window子句
♥♥♥1.row_number()
♥♥♥2.rank()
♥♥♥3.dense_rank() 同分并列
4.ntile()
♥♥♥5.lag(field,nth,defaultVal) 往前取第n个数据
♥♥♥6.lead(field,nth,defaultVal) 往后取第n个数据
7.first_value(field)
8.last_value(field)
9.nth_value(field,nth)#over重句
over([partition by field [order by field]] rows between ... and ...)...#window子句
unbounded_preceeding
n preceding
current row
n following
unbounded_following
炸裂函数(侧视图)
select...from table_name lateral view explode(field) lv_alias as item_alias;select...from table_name lateral view posexplode(field) lv_alias as pos,item_alias;
例子:
-------------------------------------------------------------------------------------------------
create table shop
(id int,
name string,
json_log string,
visit_url string)
row format delimited
fields terminated by '\t'
stored as textfile
location '/test/shop';select
id,name,vd,vp,sd
from shop
lateral view json_tuple(json_log,'visit_date','visit_product','suspending_duration') lv_jl as vd,vp,sd;select
id,name,protocol,host,qkey,qval
from shop
lateral view parse_url_tuple(visit_url,'PROTOCOL','HOST','QUERY') lv_multi as protocol,host,query
lateral view explode(str_to_map(query,'&','='))lv_query_map as qkey,qval;----------------------------------------------------------------------------------------------------