0. 说明

  Hive 的内置函数的基本操作 | 时间函数 | String 函数 | 条件语句 | explode | split | substring


1. 基本操作

  查看函数

  show functions;

  查看函数的用法

    desc function function_name;

  查看函数的扩展信息

  desc function extended format_name;

2. 时间函数

select current_database()        //当前数据库
select current_date() //当前日期
select current_timestamp() //当前时间戳,精确到毫秒
select date_format( current_timestamp(), 'yyyy-MM-dd HH:mm:ss'); //将时间格式化
select unix_timestamp(current_timestamp()); //将日期转换成时间戳,精确到秒
select from_unixtime(153361440000, 'yyyy-MM-dd'); //将时间戳转化成日期
select datediff('2018-03-01','2018-02-01'); //计算两个指定日期相差多少天

3. String 函数

select split('hello world',' ');    // 以空格进行切割成 Array 数组
select substr('hello world', 7); // 切割字符串 world select trim(' world'); //去掉前后的空格 format_number()
//select format_number(1234.345,2); => 1,234.35
//select format_number(1234.345,'000000.00'); => 001234.35
//select format_number(1234.345,'########.##'); => 1234.35 select concat('hello', ' world'); // 拼串操作,返回 hello world select length('helloworld'); // 10

4. 条件语句

  4.1 if

select if( age > 10 ,'old', 'young') from user_par;

  // 相当于三元运算符。
  // 第一个表达式成立返回第二个表达式
  // 第一个不成立返回第三个表达式

  4.2 case

select case when age<20 then 'young' when age<40 then 'middle' else 'old' end from user_par; 

  // 小于20,返回 young
  // 小于40,返回 middle
  // 否则,返回 old


5. explode

  5.1 描述

  separates the elements of array a into multiple rows
  or the elements of a map into multiple rows and columns

  分裂 array 数组的中的元素变成多行
  或者分裂 map 中的元素变成多行和多列
  是一个表生成函数

  5.2 使用方法

  explode(array)


6. split

  6.1 描述

  Splits str around occurances that match regex

  拆分与正则表达式匹配的事件

  6.2 使用方法

  split(str, regex)


7. substr

  7.1 描述

  截取从指定位置开始指定长度的的字符串

  默认从第一位开始截取

  7.2 使用方法

  substr(str, pos[, len])


[Hive_6] Hive 的内置函数应用的更多相关文章

  1. hive的内置函数和自定义函数

    一.内置函数 1.一般常用函数 .取整函数 round() 当传入第二个参数则为精度 bround() 银行家舍入法:为5时,前一位为偶则舍,奇则进. .向下取整 floor() .向上取整 ceil ...

  2. Hive学习之路 (九)Hive的内置函数

    数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIGINT valu ...

  3. Hive的内置函数

    定义: UDF(User-Defined-Function),用户自定义函数对数据进行处理. UDTF(User-Defined Table-Generating Functions) 用来解决 输入 ...

  4. hive中内置函数

    查看函数的详细使用方法 desc function extended 函数名 例如: 1).desc function extended locate locate(substr, str[, pos ...

  5. Hive内置函数和自定义函数的使用

    一.内置函数的使用 查看当前hive版本支持的所有内置函数 show function; 查看某个函数的使用方法及作用,比如查看upper函数 desc function upper; 查看upper ...

  6. [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数

    Built-in Operators Relational Operators The following operators compare the passed operands and gene ...

  7. [转] Hive 内置函数

    原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...

  8. Hive(六)内置函数与高级操作

    一内置函数 1 数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIG ...

  9. Hive 内置函数

    原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...

随机推荐

  1. man sm-notify(sm-notify命令中文手册)

    本人译作集合:http://www.cnblogs.com/f-ck-need-u/p/7048359.html sm-notify命令是用来发送重启通知信息给NFS对端的,在锁状态恢复过程中起着至关 ...

  2. Perl中的自增、自减

    自增和自减 perl也支持数值类型的自增和自减操作.不仅如此,还支持字符.字符串的自增.自减. 如果自增(++)和自减(--)符号放在数值的前面,则先增减,再返回: 如果自增(++)和自减(--)符号 ...

  3. Perl的IO操作(2):更多文件句柄模式

    open函数除了> >> <这三种最基本的文件句柄模式,还支持更丰富的操作模式,例如管道.其实bash shell支持的重定向模式,perl都支持,即使是2>&1 ...

  4. Python爬虫之多线程下载豆瓣Top250电影图片

    爬虫项目介绍   本次爬虫项目将爬取豆瓣Top250电影的图片,其网址为:https://movie.douban.com/top250, 具体页面如下图所示:   本次爬虫项目将分别不使用多线程和使 ...

  5. 第一册:lesson nineteen。

    原文:tired and thirsty. A:What's the matter,children? B:We are tired and thirsty. A:Sit down,here. Are ...

  6. 本地yum仓库搭建,使用163yum源

    如果内部网络没有连接Internet就在本地配置yum仓库 将操作系统镜像上传到服务器中,进行挂载 mount –o loop rhel-server-6.7-x86_64-dvd.iso /mnt ...

  7. 阿里分布式服务框架Dubbo的架构总结

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...

  8. mybatis全局属性(全局变量)

    mybatis全局属性(全局变量):方法1:在 properties 元素体内,使用<property>标签定义的属性方法2:在 properties 元素中, 使用 resource 或 ...

  9. favicon.ico在chrome里显示正常,在ie,edge浏览器中不显示

    代码: <head> <meta charset="UTF-8"> <link href="imgs/favicon.ico" r ...

  10. 基于timestamp和nonce的防重放攻击

    以前总是通过timestamp来防止重放攻击,但是这样并不能保证每次请求都是一次性的.今天看到了一篇文章介绍的通过nonce(Number used once)来保证一次有效,感觉两者结合一下,就能达 ...