[Hive_6] Hive 的内置函数应用
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 的内置函数应用的更多相关文章
- hive的内置函数和自定义函数
一.内置函数 1.一般常用函数 .取整函数 round() 当传入第二个参数则为精度 bround() 银行家舍入法:为5时,前一位为偶则舍,奇则进. .向下取整 floor() .向上取整 ceil ...
- Hive学习之路 (九)Hive的内置函数
数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIGINT valu ...
- Hive的内置函数
定义: UDF(User-Defined-Function),用户自定义函数对数据进行处理. UDTF(User-Defined Table-Generating Functions) 用来解决 输入 ...
- hive中内置函数
查看函数的详细使用方法 desc function extended 函数名 例如: 1).desc function extended locate locate(substr, str[, pos ...
- Hive内置函数和自定义函数的使用
一.内置函数的使用 查看当前hive版本支持的所有内置函数 show function; 查看某个函数的使用方法及作用,比如查看upper函数 desc function upper; 查看upper ...
- [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数
Built-in Operators Relational Operators The following operators compare the passed operands and gene ...
- [转] Hive 内置函数
原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...
- Hive(六)内置函数与高级操作
一内置函数 1 数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIG ...
- Hive 内置函数
原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...
随机推荐
- centos安装Nginx1.9.9
今天在安装centos的时候,又出现了yum报错的情况,弄了半个小时就弄好,就直接放弃了,使用了VMware快照功能.(快照功能要经常使用,我使用的频率不高,所以这次又造成了以前安装好的很多模块又得重 ...
- 简单说明CGI和动态请求是什么
1. CGI是什么 CGI是common gateway interface的缩写,大家都译作通用网关接口,但很不幸,我们无法见名知意. 我们知道,web服务器所处理的内容都是静态的,要想处理动态内容 ...
- MySQL系列详解三:MySQL中各类日志详解-技术流ken
前言 日志文件记录了MySQL数据库的各种类型的活动,MySQL数据库中常见的日志文件有 查询日志,慢查询日志,错误日志,二进制日志,中继日志 .下面分别对他们进行介绍. 查询日志 1.查看查询日志变 ...
- 脚本解决.NET MVC按钮重复提交问题
见于:Avoiding Duplicate form submission in Asp.net MVC by clicking submit twice 脚本代码: $(document).on(' ...
- log4j-1.2.6升级到log4j-2.9.0
0.工程是普通java web工程,不是maven工程.需要升级log4j 步骤发下: 1. 在build path中 移除项目对log4j-1.2.6.jar的引用,并物理删除log4j-1.2.6 ...
- 关于EF中出现FOREIGNKEY约束可能会导致循环或多重级联路径的问题
ef中,我们创建外键的时候需要注意,否则会出现标题所示问题. 例:有项目表,项目收藏表,用户表 项目表有如下字段:ProjectId,InputPersonId等 项目收藏表有如下字段:Project ...
- 关于我空间那篇名为《JavaScript axError:Unexpected token ILLEGAL 很简单的代码……》的随笔
如图所示,我是空间的那片随笔,这里就不贴出链接了,也不希望你有这个兴趣,不知道会不会有人无意间闯入,额,自从日志用windows live writer 2009 发了那篇随笔后,我在网页上一直没能正 ...
- SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embe
问题描述 *************************** APPLICATION FAILED TO START *************************** Description ...
- mybatis_ The content of element type association must match (constructor,id,result,ass ociation,collection,discriminator)
一般遇到这种问题肯定要看一看association中元素编写顺序, <resultMap id="orderRslMap" type="orders"&g ...
- 【Java每日一题】20170209
20170208问题解析请点击今日问题下方的“[Java每日一题]20170209”查看(问题解析在公众号首发,公众号ID:weknow619) package Feb2017; public cla ...