hive中正则表达式怎么用

发布时间:2021-12-10 11:52:42 作者:小新
来源:亿速云 阅读:340

小编给大家分享一下hive中正则表达式怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

 hive中的正则表达式还是很强大的。数据工作者平时也离不开正则表达式。对此,特意做了个hive正则表达式的小结。所有代码都经过亲测,正常运行。

2.regexp_extract

语法: regexp_extract(string subject, string pattern, int index) 
返回值: string 
说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。

hive> select regexp_extract('IloveYou','I(.*?)(You)',1) from test1 limit 1;
Total jobs = 1
。。。
Total MapReduce CPU Time Spent: 7 seconds 340 msec
ok
love
Time taken: 28.067 seconds, Fetched: 1 row(s)

hive> select regexp_extract('IloveYou','I(.*?)(You)',2) from test1 limit 1;
You
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',1) from test1 limit 1;
I
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',0) from test1 limit 1;
IloveYou

hive> select regexp_replace("IloveYou","You","") from test1 limit 1;
Ilove

<h3 id="3regexpreplace" font-weight:300;line-height:1.1;color:#3F3F3F;font-size:2.15em;white-space:normal;background-color:#FFFFFF;"> 3.regexp_replace

语法: regexp_replace(string A, string B, string C) 
返回值: string 
说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,类似oracle中的regexp_replace函数。


hive> select regexp_replace("IloveYou","You","") from test1 limit 1;
Ilove
hive> select regexp_replace("IloveYou","You","lili") from test1 limit 1;
Ilovelili

以上是“hive中正则表达式怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. Hive中matadata怎么用
  2. HIVE中left semi join怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hive 正则表达式

上一篇:hadoop Yarn调度器Scheduler的特点是什么

下一篇:hadoop reduce个数控制怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》