hive的相关函数

一、内置函数
1、数学函数

(1)round:四舍五入
         select round(数值,小数点位数);
(2)ceil:向上取整
       select ceil(45.6); --46
(3)floor:向下取整
       select floor(45.6); --45
2、字符函数
(1)lower:转成小写
     select lower('Hive'); --hive
(2)upper:转成大写
     select lower('Hive'); --HIVE
(3)length:长度
     select length('Hive'); --4    
(4)concat:拼接字符串
    select concat('hello','Hive'); --helloHive
(5)substr:求子串
     select substr('hive',2); --ive
     select substr('hive',2,1); --i
 (6)trim:去掉前后的空格
         select trim('  hive   '); -hive
 (7)lpad:左填充
          对hive填充到10位,补位用#
    select lpad('hive',10,'#'); --######hive
 (8)rpad:右填充
       select rpad('hive',10,'#'); --hive######
3、收集函数 
select size(map(1,'yy',2,'xx')); --2 map结合的元素个数
4、转换函数
select cast(1 as float); --1.0
select cast('2016-05-22' as date); --2016-05-22
5、日期函数
(1)to_date
    select to_date('2015-05-22 15:34:23'); --2015-05-22
 (2)year
    select year('2015-05-22 15:34:23'); --2015
 (3)month
    select month('2015-05-22 15:34:23'); --5
 (4)day
    select day('2015-05-22 15:34:23'); --22
 (5)weekofyear
    select weekofyear('2015-05-22 15:34:23'); --21
  (6)datediff
    select datediff('2015-05-22 15:34:23','2015-05-29 15:34:23'); --[-7]
 (7)date_add
    select date_add('2015-05-22 15:34:23',2); --2015-05-24
 (8)date_sub
    select date_sub('2015-05-22 15:34:23',2); --2015-05-20
6、条件函数
coalesce:从左到右返回第一个不为null的值

case...when...:条件表达式

select ename,job,sal,
           case job when 'president' then sal+100
            when 'manager'    then sal+800
            else sal+400
        end
    from emp;
二、聚合函数
(1)count:总数
(2)sum:和
(3)max:最大值
(4)min:最小值
(5)avg:平均数
  转换成MR作业
三、表生成函数  
select explode(map(1,'xx',2,'yy',3,'zz'));
   转换成MR作业,其结果如下
1    xx
2    yy
3    zz
--------------------- 

来源:CSDN 
原文:https://blog.csdn.net/yyywyr/article/details/51475410 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值