Hive常用函数

1、解析URL字符串的: parse_url

用法:

selectparse_url("",[HOST,PATH,QUERY,REF,PROTOCOL,FILE,AUTHORITY,USERINFO])

举例 :

selectparse_url('http://facebook.com/path/p1.php?query=1','PROTOCOL')from dual; 

---http

selectparse_url('http://facebook.com/path/p1.php?query=1','HOST')fromdual;

---facebook.com

selectparse_url('http://facebook.com/path/p1.php?query=1','REF')fromdual; 

---空

selectparse_url('http://facebook.com/path/p1.php?query=1','PATH')fromdual; 

---/path/p1.php

selectparse_url('http://facebook.com/path/p1.php?query=1','QUERY')fromdual; 

---空

selectparse_url('http://facebook.com/path/p1.php?query=1','FILE')fromdual;

---/path/p1.php?query=1

selectparse_url('http://facebook.com/path/p1.php?query=1','AUTHORITY')fromdual;

---facebook.com

selectparse_url('http://facebook.com/path/p1.php?query=1','USERINFO')fromdual;

 ---空

2、字符串连接函数(需要String类型): concat和concat_ws

用法:

concat(str1,SEP,str2,SEP,str3,……)   或者  

concat_ws(SEP,str1,str2,str3, ……) (SEP为连接符)

举例:

selectconcat('江苏省','-','南京市','-','玄武区','-','徐庄软件园'); 

---江苏省-南京市-玄武区-徐庄软件园

selectconcat_ws('-','江苏省','南京市','玄武区','徐庄软件园');   

---江苏省-南京市-玄武区-徐庄软件园

3、当前的系统时间:unix_timestamp()  from_unixtime

用法:

unix_timestamp()  或者  

from_unixtime(unix_timestamp(),"patten")

举例:

selectunix_timestamp()

---1484532291

selectfrom_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); 

---2020-12-12 08:32:15

4、字符串替换函数(将字符串A 中的B 用 C 替换):regexp_replace

用法:

regexp_replace(string A, string B, string C)

举例:

selectregexp_replace('www.tuniu.com','tuniu','jd');   

---www.jd.com

5、重复N次字符串:repeat

用法:

repeat(string str,intn)

举例:

selectrepeat('ab',3); 

---ababab

6、补齐字符串:lpad  rpad

用法:

lpad(string str,intlen, string pad)

或者

rpad(string str,intlen, string pad)

举例:

selectlpad('ab',7,'k');        ---kkkkkab

selectrpad('ab',7,'k');        ---abkkkkk

7、 删除字符串两边的空格(中间的会保留):trim

用法:

trim(string A), ltrim(string A) ,rtrim(string A)

举例:

selecttrim('   kim   bo   ')  ---kim   bo

selectltrim('   kim   bo   ')  ---kim   bo

selectrtrim('   kim   bo   ')  ---   kim   bo

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 文章目录 1 关系运算1.1 1、等值比较: =1.2 2、不等值比较:1.3 3、小于比较:1.4 4、小于等于...
    叫我老村长阅读 886评论 0 2
  • 本篇文章长更,欢迎大家收藏和喜欢 2018.12.25 字符串函数2 1.正则表达式解析函数:regexp_ext...
    清听阅读 4,283评论 0 1
  • 关系运算 1、等值比较: = 语法:A=B操作类型:所有基本类型描述: 如果表达式A与表达式B相等,则为TRUE;...
    phylicia2018阅读 452评论 0 0
  • 1、系统内置函数1.查看系统自带的函数hive> show functions;2.显示自带的函数的用法hive>...
    我还不够强阅读 889评论 0 0
  • 目录:一、关系运算二、数学运算三、逻辑运算四、复杂的数据类型 array、map、struct五、复杂类型访问操作...
    夜希辰阅读 1,356评论 1 6