hive函数及性能优化

hive函数分类

从输入输出角度分类
标准函数:一行数据中的一列或多列为输入,结果为单一值
聚合函数:多行的零列到多列为输入,结果为单一值
表生成函数:零个或多个输入,结果为多列或多行
从实现方式分类
内置函数
自定义函数
UDF:自定义标准函数
UDAF:自定义聚合函数
UDTF:自定义表生成函数
hive提供了大量内置函数供开发者使用
标准函数:字符函数、类型转换函数、数学函数、日期函数、集合函数、条件函数
聚合函数
表生成函数
具体见文章:https://www.cnblogs.com/MOBIN/p/5618747.html

select concat('abc','cd','fff') | abccdfff
select instr('abcdabcd','cd')    |    3
select length('cd','abcdabcd',4)       |       6
select locate('cd','abcdabcd',4)      |     7
select upper('abcdef')     ABCDEF
select lower('ABCDef')     abcdef
select regexp_replace('1999/5.6','[/|\\.]','-')   []代表字符选择器     1999-5-6
	select regexp_replace('1999/5/6 13:24:56.234','\\.[0-9]+','').234去掉
select split('1999/5/6 13:24:56.234','\\.')[0]          1999/5.6 13:24:56
select substring('1999/5/6 13:24:56.234',1,8)       1999/5/6     java左包右不包
select trim('   1999/5/6 13:24:56.234    ')      去除前后的空格
select str_to_map('1999/5/6 13:24:56.234',' ')        将字符串转换成map格式
	select str_to_map('a:b,c:d')    "a":"b","c":"d"
select encode('你好','utf-8')      你好
select reverse('你好')      好你
select ltrim('   abc')     去除左边的空格         rtirm('abc    ')      去除右边的空格
正则的作用:查找、替换、匹配、截取
select regexp_extract('1999-5-6 13:14:56.001','([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}) ([0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})(\\.[0-9]{2,3})',3)
select format_number('1234567.45678',3)      1,234,567.457
select repeat('abc',3)      abcabcabc
select get_json_object('{"name":"zs","age":"40"}','$.name')     zs
select lpad('abcd',10,'0')       000000abcd左填充    rpad右填充
select lpad('abcd',3,'0')        abc不够长左截取     rpad不够长右截取
select parse_url('http://www.taobao.com','HOST')    www.taobao.com取网址
select parse_url('http://www.taobao.com?userid=1&v=2','QUERY')    userid=1&v=2取参数
select parse_url('http://www.taobao.com?userid=1&v=2','PROTROCY') as info  
select sentences('hello world!how do you do')     [["hello","world"],["how","do","you","do"]]
select initcap('hello world, how do you do')    Hello World,How Do You Do   首字母大写
select round(2.14158,3)   四舍五入保留3位小数,后面不写默认保留两位
select floor(2.9415)     向下取整2
select ceil(2.1415)      向上取整3
select rand()0-1之间的随机浮点数     rand(10)0-10之间的随机浮点数,每次都一样
java平时的随机数是以当前时间戳为序列,是随着时间变,给了10之后是以10为序列,第一次随机完了之后就一直是同一个数,10就是种子seed
select sqrt(9)    开根号3    select sqrt(-10)    null 
select pow(10,2)     10的平方100
select pmod(3,2)     求模1        数据库为mod
select cast("123" as int)+20     数据类型转换143     
	select cast("123" as string)+20    +可以自动做数据类型转换
	select cast("123abc" as int)      null
select from_unixtime(1250111000)     时间戳转成年月日时分秒2009-08-13 14:18:36
	select from_unixtime(1250111000,'yyyy-MM-dd'),unix_timestamp()      2009-08-13,获取当前时间戳
select unix_timestamp('1999-9-9 1:0:34')    获取1999-9-9 1:0:34的时间戳
	select unix_timestamp('1999-1-1 8:0:0')   时间戳为0
select to_date(from_unixtime(unix_timestamp()))    获取当前日期,按一定格式输出2020-06-15
select year(from_unixtime(unix_timestamp()))    取年2020
select month(from_unixtime(unix_timestamp()))    取月06
select day(from_unixtime(unix_timestamp()))     取日15
select weekofyear(from_unixtime(unix_timestamp()))     今天是本年的第几周
select current_date()    当前日期2020-06-15
select datediff(current_date(),'2020-5-12')     两个日期相减 34
select date_add(curent_date(),2)     当前日期加两天     2020-06-17
select date_sub(current_date(),2)     当前日期减两天
select current_timestamp()     当前时间戳2020-06-15 12:01:15
select add_months(current_date(),6)   当前月份加6个月
select last_day(current_date())    获取当前月份的最后一天
select next_day(curent_date(),'MO')   获取下个星期几的日期
select trunc(current_date(),'MM')    截取当前月份,后面自动补1   2020-06-01
	select trunc(current_date(),'YY')   获取当前年份   2020-01-01
select months_between(current_date(),'2020-12-31')   -6.516   差了6.526个月,前减后   算前后相差几个月
select date_format(current_date(),'m')    获取月    'd','y','h','s',   只精确年月日,时分秒不精确

select size(split('hello world how do you do',' '))     6 先分割再计算长度
select if(1>2,'hello','world')     world
select nvl(null,10)   如果为10就返回空    =if null(mysql)    nvl(1,10)返回1,不空填后面的值,空返回前面的值
	select ifnull(null,10)   返回10
select coalesce(null,null,null,10,null,20)     返回第一个不为空的值10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值