hive函数整理

趁着离职前夕的空档,整理了hive的所有函数,有很多新的发现,后面不断温习吧。

一、函数help

  1. desc function XX 显示函数描述信息

hive> desc function concat;
OK
concat(str1, str2, … strN) - returns the concatenation of str1, str2, … strN or concat(bin1, bin2, … binN) - returns the concatenation of bytes in binary data bin1, bin2, … binN

  1. desc function extended XX 显示函数详细描述信息

hive> desc function extended concat;
OK
concat(str1, str2, … strN) - returns the concatenation of str1, str2, … strN or concat(bin1, bin2, … binN) - returns the concatenation of bytes in binary data bin1, bin2, … binN
Returns NULL if any argument is NULL.
Example:
SELECT concat(‘abc’, ‘def’) FROM src LIMIT 1;
‘abcdef’

所有函数都可以根据以上语句查阅语法和例子。

二、有特色的函数
2.1 时间函数
2.1.1 add_months(start_date, num_months) 日期的月份加减

hive> SELECT add_months(‘2009-04-02’, 1);
OK
2009-05-02

hive> SELECT add_months(‘2009-01-31’, 1);
OK
2009-02-28

hive> SELECT add_months(‘2009-01-31’, -1);
OK
2008-12-31

2.1.2 current_date() 当前日期(yyyy-mm-dd)
current_timestamp() 当前日期(yyyy-mm-dd hh:mm:ss.sss)

2.1.3 last_day(date) 日期date所在月份的最后一天

select last_day(‘2019-02-25’);
OK
2019-02-28

2.1.4 next_day(start_date, day_of_week) 生成日期start_date之后的第一个规定星期所对应日期

SELECT next_day(‘2019-03-28’,‘friday’);
OK
2019-03-29

2.1.5 trunc(date, fmt) 按精度fmt对date进行处理,只保留年份或月份(fmt=‘MONTH’/‘MON’/'MM’为月份,fmt=‘YEAR’/‘YYYY’/'YY’为年份)

SELECT trunc(‘2009-02-25’, ‘MM’);
OK
2009-02-01

2.2 数学函数
2.2.1 cbrt(double) 开方

hive> select cbrt(8);
OK
2.0

2.2.2 ceil(x) 或ceiling(x) 向上取整,即取不小于x的最小整数
floor(x) 向下取整

hive> select ceil(4.5);
OK
5

hive> select ceil(-4.5);
OK
-4

2.2.3 conv(num, from_base, to_base) 进制转换函数(to_base如果为负数,则取正处理)

hive> select conv(17,10,2);
OK
10001

hive> select conv(17,10,-2);
OK
10001

2.2.4 a div b a除以b的商(忽略余数)

2.2.5 greatest(v1, v2, …) 一组数的最大值
least(v1, v2, …) 一组数的最小值

hive> select greatest(1,3,4,5);
OK
5

2.2.6 histogram_numer

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值