ALTER TABLE table1 DROP PARTITION (day='2015-07-14');
ALTER TABLE table1 ADD COLUMNS (visit int);
解码url
reflect("java.net.URLDecoder", "decode", url,"UTF-8")
CASE WHEN b.user_account is null then 0 else b.user_account end
parse_url(concat(uri), 'QUERY', 'siteid') uri必须以http开头,当不存在siteid参数是返回NULL
first_value(a) OVER(PARTITION BY ORDER BY t.cnt desc)
sort_array(collect_set(url) OVER(PARTITION BY cookie ORDER BY createtime))
一行转多列
explode(ARRAY) 列表中的每个元素生成一行
explode(MAP) map中每个key-value对,生成一行,key为一列,value为一列
lateral view用于和split, explode等UDTF一起使用,它能够将一行数据拆成多行数据,在此基础上可以对拆分后的数据进行聚合。lateral view首先为原始表的每行调用UDTF,UTDF会把一行拆分成一或者多行,lateral view再把结果组合,产生一个支持别名表的虚拟表。
例如:
SELECT pageid, adid FROM pageAds LATERAL VIEW explode(adid_list) adTable AS adid;
SELECT myCol1, myCol2 FROM baseTable
LATERAL VIEW explode(col1) myTable1 AS myCol1
LATERAL VIEW explode(col2) myTable2 AS myCol2;
多列转一行
select max(ubi.id), ubi.name, concat_ws(',', collect_set(ua.address)) as address from user_basic_info ubi join user_address ua on ubi.name=ua.name group by ubi.name;