日期函數(shù):
to_date()? ??
從一個(gè)字符串中抽取日期的部分效扫;to_date(‘2019-03-09 wedede’);
year(),month()庆揩,day()俏脊,hour(),minute(),second()
抽取年缩宜、月褒颈、日不跟、時(shí)颓帝、分、秒
weekofday()
返回輸入日期在改年中第幾個(gè)星期窝革。
datediff
兩個(gè)日期相減购城,返回相差的天數(shù)
date_add()、date_sub()
在一個(gè)日期上增加(減少)天數(shù)虐译,返回增加天數(shù)后的日期瘪板;
from_unixtime()
轉(zhuǎn)化成unix時(shí)間戳
unix_timestap()
unix_timestap()獲取當(dāng)前時(shí)間的時(shí)間戳
unix_timestap(stringdate) ;返回指定日期的時(shí)間戳
date_format
date_farmat(‘2019-02-10’,’yyyy-mm’);按照想要的格式漆诽,格式化日期侮攀,第二個(gè)參數(shù)為格式
next_day()
next_day(‘2019-02-10’,’mo’);取當(dāng)前日期的下一個(gè)周一厢拭;周幾可以指定兰英,第二個(gè)參數(shù)表示指定周幾
last_day()
last_day(‘2019-03-23’);獲取當(dāng)前月的最后一天
數(shù)學(xué)函數(shù):
round()
四舍五入
round(number)返回int
round(number,int a)? 返回精度為a的double值
ceil()
向上取整
floor()
向下取整
字符串函數(shù):
concat()? 重要
concat(string a,string b,…..)供鸠;參數(shù)個(gè)數(shù)不限畦贸,將各個(gè)字符串連接
concat_ws()? 重要
concat_ws(‘指定分割符’,要合并的列,....)回季;按照相同的key將value按照分隔符合并家制,參數(shù)個(gè)數(shù)不限
length()
length(string a);計(jì)算字符串的長度
substr()泡一、substring()
substr(a,b)? 從字符串a(chǎn)中颤殴,第b位開始獲取
substr(a,b,c)? 從字符串a(chǎn) 中,第b位開始取鼻忠,取c個(gè)字符
reverse()
reverse(string a)涵但;將字符創(chuàng)a 反轉(zhuǎn)
upper()、ucase()
upper(string a )帖蔓;返回字符串a(chǎn)的大寫
lower()矮瘟、lcase()
lower(string a );返回字符串a(chǎn)的小寫
trim()? 重要
去掉左右指定的字符
trim(string a):去掉字符串兩邊的空格?
trim(string a,’指定字符’)?
ltrim()
去掉左邊指定的字符
ltrim(string a):去掉字符串左邊的空格
ltrim(string a,’指定字符’)?
rtrim()
去掉右邊指定的字符
rtrim(string a):去掉字符串右邊的空格
rtrim(string a,’指定字符’)?
regexp_replace()
regexp_replace(string a,string b,string c)塑娇;將字符串a(chǎn)中的符合java正則表達(dá)式b的部分替換為c
regexp_extract()
regexp_extract(string subject,string pattern,int index)澈侠;將字符串subject按照pattern正則表達(dá)式的規(guī)則拆分,返回index指定的字符
lpad(),rpad()
左填充函數(shù)埋酬,右填充函數(shù)哨啃,lpad(‘string a’,int b,’string c’);b表示字符串的長度烧栋,如果a的長度不夠用字符串c填充,
repeat()
repeat(string str,int n)拳球;返回重復(fù)n次后的str字符串
ascii()
acsii(string str)审姓;返回str第一個(gè)字符的ascii值
space()
space(int n);返回空格數(shù)為n的字符串
split()
split(string a,string pat)祝峻;按照pat字符串分割str魔吐,返回分割后的字符串?dāng)?shù)組
find_in_set()
find_in_set(string str,string strlist);返回str在strlist第一次出現(xiàn)的位置莱找,返回值是int
Collect_list()
Collect_list()酬姆;返回具有重復(fù)項(xiàng)的的對象列表
Collect_set()
Collect_set();返回消除重復(fù)元素的列表
Str_to_map()? ?重要
Str_to_map(字符串參數(shù),分隔符1宋距,分隔符2)轴踱;分隔符1將將字符串分割成k-v對,分隔符2 分割每個(gè)k-v對谚赎,分隔符默認(rèn)使用‘,’诱篷,分隔符2默認(rèn)使用‘=’?? 【字符串轉(zhuǎn)化為map】
lateral view? 重要
可以理解為循環(huán)壶唤,將炸開后的array或者map中的數(shù)據(jù)遍歷出來
多個(gè)literal view就會(huì)形成循環(huán)的嵌套,以笛卡爾積的形式遍歷結(jié)果
explode()? 重要
通常與lateral view一起使用棕所,將array或者map中的數(shù)據(jù)炸開闸盔,
條件函數(shù):
if
if(判斷條件,true則,false則)
case when
case when 條件1 then 結(jié)果1
??? when條件2 then 結(jié)果2
??? else?
? 結(jié)果3
??? end
coalesce()
coalesce(t? v1,tv2,……)? ;返回參數(shù)中第一個(gè)非空值的參數(shù),如果都是空則返回null
【注】
空值的判斷:is null
非空值的判斷is not null