日期函数:
to_date()
从一个字符串中抽取日期的部分;to_date(‘2019-03-09 wedede’);
year(),month(),day(),hour(),minute(),second()
抽取年、月、日、时、分、秒
weekofday()
返回输入日期在改年中第几个星期。
datediff
两个日期相减,返回相差的天数
date_add()、date_sub()
在一个日期上增加(减少)天数,返回增加天数后的日期;
from_unixtime()
转化成unix时间戳
unix_timestap()
unix_timestap()获取当前时间的时间戳
unix_timestap(stringdate) ;返回指定日期的时间戳
date_format
date_farmat(‘2019-02-10’,’yyyy-mm’);按照想要的格式,格式化日期,第二个参数为格式
next_day()
next_day(‘2019-02-10’,’mo’);取当前日期的下一个周一;周几可以指定,第二个参数表示指定周几
last_day()
last_day(‘2019-03-23’);获取当前月的最后一天
数学函数:
round()
四舍五入
round(number)返回int
round(number,int a) 返回精度为a的double值
ceil()
向上取整
floor()
向下取整
字符串函数:
concat() 重要
concat(string a,string b,…..);参数个数不限,将各个字符串连接
concat_ws() 重要
concat_ws(‘指定分割符’,要合并的列,....);按照相同的key将value按照分隔符合并,参数个数不限
length()
length(string a);计算字符串的长度
substr()、substring()
substr(a,b) 从字符串a中,第b位开始获取
substr(a,b,c) 从字符串a 中,第b位开始取,取c个字符
reverse()
reverse(string a);将字符创a 反转
upper()、ucase()
upper(string a );返回字符串a的大写
lower()、lcase()
lower(string a );返回字符串a的小写
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中的符合java正则表达式b的部分替换为c
regexp_extract()
regexp_extract(string subject,string pattern,int index);将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符
lpad(),rpad()
左填充函数,右填充函数,lpad(‘string a’,int b,’string c’);b表示字符串的长度,如果a的长度不够用字符串c填充,
repeat()
repeat(string str,int n);返回重复n次后的str字符串
ascii()
acsii(string str);返回str第一个字符的ascii值
space()
space(int n);返回空格数为n的字符串
split()
split(string a,string pat);按照pat字符串分割str,返回分割后的字符串数组
find_in_set()
find_in_set(string str,string strlist);返回str在strlist第一次出现的位置,返回值是int
Collect_list()
Collect_list();返回具有重复项的的对象列表
Collect_set()
Collect_set();返回消除重复元素的列表
Str_to_map() 重要
Str_to_map(字符串参数,分隔符1,分隔符2);分隔符1将将字符串分割成k-v对,分隔符2 分割每个k-v对,分隔符默认使用‘,’,分隔符2默认使用‘=’ 【字符串转化为map】
lateral view 重要
可以理解为循环,将炸开后的array或者map中的数据遍历出来
多个literal view就会形成循环的嵌套,以笛卡尔积的形式遍历结果
explode() 重要
通常与lateral view一起使用,将array或者map中的数据炸开,
条件函数:
if
if(判断条件,true则,false则)
case when
case when 条件1 then 结果1
when条件2 then 结果2
else
结果3
end
coalesce()
coalesce(t v1,tv2,……) ;返回参数中第一个非空值的参数,如果都是空则返回null
【注】
空值的判断:is null
非空值的判断is not null