Hive 常用函数
参考地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
1. parse_url(url, partToExtract[, key])
2. concat(str1,SEP,str2,SEP,str3,……) 和 concat_ws(SEP,str1,str2,str3, ……)
字符串连接函数,需要是 string型字段。
如果4个字段,想得到如下结果,看下两个函数的区别:
eg: 

代码1: select concat('江苏省','-','南京市','-','玄武区','-','徐庄软件园');
代码2: select concat_ws('-','江苏省','南京市','玄武区','徐庄软件园');
结论:当连接的内容(字段)多于2个的时候,concat_ws的优势就显现了,写法简单、方便。
3. unix_timestamp() 当前系统时间
unix_timestamp() 是将当前系统时间转换成数字型秒数,from_unixtime 将数字型按照 格式进行时间转换。
eg:

代码:select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');
4. regexp_replace(string A, string B, string C) 字符串替换函数,将字符串A 中的B 用 C 替换。
eg: 
代码:select regexp_replace('www.tuniu.com','tuniu','jd');
5. repeat(string str, int n) 重复N次字符串
eg:
代码:select repeat('ab',3);
6. lpad(string str, int len, string pad) 将字符串str 用pad进行左补足 到len位(如果位数不足的话)
eg:
代码:select lpad('ab',7,'k');
7. rpad(string str, int len, string pad) 将字符串str 用pad进行右补足 到len位(如果位数不足的话)
eg:
代码:select rpad('ab',7,'k');
8. trim(string A) 删除字符串两边的空格,中间的会保留。
相应的 ltrim(string A) ,rtrim(string A)
eg:
9. to_date(string timestamp) 将时间戳转换成日期型字符串
eg:
代码:select to_date('2017-01-16 09:55:54');
10. datediff(string enddate, string startdate) 返回int 的两个日期差
eg:
代码:select datediff('2017-01-16', '2017-01-10');
11. date_add(string startdate, int days) 日期加减
eg:
代码:select date_add('2017-01-10', 7);
12. current_timestamp 和 current_date 返回当前时间戳,当前日期
eg:
13. date_format(date/timestamp/string ts, string fmt) 按照格式返回字符串
eg: 
代码:select date_format('2017-01-16 09:55:54', 'yyyy-MM-dd');
14. last_day(string date) 返回 当前时间的月末日期
eg:
代码:select last_day('2017-01-16 09:55:54');
15. if(boolean testCondition, T valueTrue, T valueFalseOrNull) ,根据条件返回不同的值
eg: 
16. nvl(T value, T default_value) 如果T is null ,返回默认值
17. length(string A) 返回字符串A的长度
eg:
代码:select length('kimbo');
18. greatest(T v1, T v2, ...) 返回最大值,会过滤null
eg:
代码:select greatest('2016-01-01',NULL,'2017-01-01');
19. least(T v1, T v2, ...) 返回最小值,会过滤null
eg: 
代码:select least('2016-01-01',NULL,'2017-01-01','2015-01-01');
20. rand(), 返回0-1的随机值。rand(INT seed) 返回固定的随机值。
eg:
21. md5(string/binary) hive 1.3以上版本,返回md5码
22. split(str, regex) ,安装规则截取字符串,返回数组
eg:
代码:select split('ab-cd','-')[0];
Hive 常用函数的更多相关文章
- Hive常用函数的使用
Hive常用函数的使用 文章作者:foochane 原文链接:https://foochane.cn/article/2019062501.html 1 基本介绍 1.1 HIVE简单介绍 Hive ...
- hive常用函数 wordCount--Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战
第三天笔记 第三天笔记 SQL练习Hive 常用函数关系运算数值计算条件函数日期函数重点!!!字符串函数Hive 中的wordCount1.1 Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战 ...
- Hive常用函数
字符串函数 字符串长度函数:length 语法: length(string A) 返回值: int 说明:返回字符串A的长度 举例: hive> select length(‘abcedfg’ ...
- orcale和hive常用函数对照表(?代表未证实)
函数分类 oracle hive 说明 字符函数 upper('coolszy') upper(string A) ucase(string A) 将文本字符串转换成字母全部大写形式 lower('K ...
- Hive 常用函数汇总
Hive内部提供了很多函数给开发者使用,包括数学函数,类型转换函数,条件函数,字符函数,聚合函数,表生成函数等等,这些函数都统称为内置函数. 目录 数学函数 集合函数 类型转换函数 日期函数 条件函数 ...
- hive常用函数六
cast 函数: 类型转换函数,cast(kbcount as int); case when: 条件判断,case when kbcount is not null and cast(kbcount ...
- hive常用函数五
复合类型构建操作 1. Map类型构建: map 语法: map (key1, value1, key2, value2, …) 说明:根据输入的key和value对构建map类型 举例: hive& ...
- hive常用函数四
字符串函数 1. 字符串长度函数:length 语法: length(string A) 返回值: int 说明:返回字符串A的长度 举例: hive> select length('abced ...
- hive常用函数三
日期函数 1. UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string ...
随机推荐
- 飘逸的python - zlib压缩存到数据库
当每天有大量的数据存到kv数据库中去,且value数据很大,于是想压缩后再存进去. 之前提到了 gzip压缩,为什么不直接用gzip呢. 其实更确切的说gzip是一种文件格式,它压缩成gzip文件,而 ...
- poj 3897 Maze Stretching 二分+A*搜索
题意,给你一个l,和一个地图,让你从起点走到终点,使得路程刚好等于l. 你可以选择一个系数,把纵向的地图拉伸或收缩,比如你选择系数0.5,也就是说现在上下走一步消耗0.5的距离,如果选择系数3,也就是 ...
- 64位linux报错Could not initialize class java.awt.image.BufferedImage
最近碰到一个问题: 64位linux报错Could not initialize class java.awt.image.BufferedImage 在WIN平台下运行正常BufferedImage ...
- [Node.js]REPL(交互式解释器)
摘要 REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux shell,我们可以在终端中输入命令,并接收系统的 ...
- Server Tomcat v6.0 at localhost was unable to start within 45 seconds
在eclipse里启动tomcat的时候出现以下的错误: Server Tomcat v6.0 at localhost was unable to start within 45 seconds. ...
- Python学习笔记---形式参数(parameter)和实际参数(argument)
def mydemo(name): '函数定义过程中的name是叫形参' #因为它只是一个形式,表示占据一个参数位置 print('传递进来的' + name + '叫做实参,因为它是具体的参数值!' ...
- oracle if else 判断
CREATE OR REPLACE FUNCTION fn_GetClassifyBymxmjazfs (v_azfs varchar2,v_mx varchar2,v_mj varchar2) re ...
- node.JS中配置http-server
http-server 是一个简单的HTTP服务器, 基于 nodeJs,在nodejs命令行中配置http服务器. 项目结构:
- java学习笔记-set
//东软实训前,要把java 看完. //2015年4月29日21:44:13 //list01 package com.alfredsun.first.main; import java.util. ...
- nodeValue、firstChild和lastChild属性
nodeValue属性如果想改变一个文本节点的值,那就使用DOM提供的nodeValue属性,他用来得到(和设置)一个节点的值:node.nodeValue但是有个细节必须注意:在用nodeValue ...