欢迎投稿

今日深度:

hive的内置函数,

hive的内置函数,


在Hive中,函数包括以下类型:

一、内置函数

1、数学函数

[plain] view plain copy
  1. (1)round:四舍五入  
  2.          select round(数值,小数点位数);  
  3. (2)ceil:向上取整  
  4.        select ceil(45.6); --46  
  5. (3)floor:向下取整  
  6.        select floor(45.6); --45  
2、字符函数

[plain] view plain copy
  1. (1)lower:转成小写  
  2.      select lower('Hive'); --hive  
  3. (2)upper:转成大写  
  4.      select lower('Hive'); --HIVE  
  5. (3)length:长度  
  6.      select length('Hive'); --4   
  7. (4)concat:拼接字符串  
  8.     select concat('hello','Hive'); --helloHive  
  9. (5)substr:求子串  
  10.      select substr('hive',2); --ive  
  11.      select substr('hive',2,1); --i  
  12.  (6)trim:去掉前后的空格  
  13.          select trim('  hive   '); -hive  
  14.  (7)lpad:左填充  
  15.           对hive填充到10位,补位用#  
  16.     select lpad('hive',10,'#'); --######hive  
  17.  (8)rpad:右填充  
  18.        select rpad('hive',10,'#'); --hive######  
3、收集函数 

[plain] view plain copy
  1. select size(map(1,'yy',2,'xx')); --2 map结合的元素个数  
4、转换函数

[plain] view plain copy
  1. select cast(1 as float); --1.0  
  2. select cast('2016-05-22' as date); --2016-05-22  
5、日期函数

[plain] view plain copy
  1. (1)to_date  
  2.     select to_date('2015-05-22 15:34:23'); --2015-05-22  
  3.  (2)year  
  4.     select year('2015-05-22 15:34:23'); --2015  
  5.  (3)month  
  6.     select month('2015-05-22 15:34:23'); --5  
  7.  (4)day  
  8.     select day('2015-05-22 15:34:23'); --22  
  9.  (5)weekofyear  
  10.     select weekofyear('2015-05-22 15:34:23'); --21  
  11.   (6)datediff  
  12.     select datediff('2015-05-22 15:34:23','2015-05-29 15:34:23'); --[-7]  
  13.  (7)date_add  
  14.     select date_add('2015-05-22 15:34:23',2); --2015-05-24  
  15.  (8)date_sub  
  16.     select date_sub('2015-05-22 15:34:23',2); --2015-05-20  
6、条件函数

coalesce:从左到右返回第一个不为null的值

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

[plain] view plain copy
  1. select ename,job,sal,  
  2.            case job when 'president' then sal+100  
  3.             when 'manager'  then sal+800  
  4.             else sal+400  
  5.         end  
  6.     from emp;  

二、聚合函数

[plain] view plain copy
  1. (1)count:总数  
  2. (2)sum:和  
  3. (3)max:最大值  
  4. (4)min:最小值  
  5. (5)avg:平均数  
  转换成MR作业

三、表生成函数  

[plain] view plain copy
  1. select explode(map(1,'xx',2,'yy',3,'zz'));  
   转换成MR作业,其结果如下

[plain] view plain copy
  1. 1   xx  
  2. 2   yy  
  3. 3   zz  

www.htsjk.Com true http://www.htsjk.com/hive/37025.html NewsArticle hive的内置函数, 在Hive中,函数包括以下类型: 一、内置函数 1、数学函数 [plain]  view plain  copy (1)round:四舍五入            select round(数值,小数点位数);   (2)ceil:向上取...
相关文章
    暂无相关文章
评论暂时关闭