从配置单元中的文本列中提取子字符串 [英] extracting a substring from a text column in hive
本文介绍了从配置单元中的文本列中提取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在名为title的列中有文本数据,如下所示
We have text data in a column named title like below
"id":"S-1-98-13474422323-33566802","name":"uid=Xzdpr0,ou=people,dc=vm,dc=com","shortName":"XZDPR0","displayName":"Jund Lee","emailAddress":"jund.lee@bm.com","title":"Leading Product Investor"
需要从蜂巢中的上述文本数据中仅提取显示名称(在此示例中为Jund Lee),我尝试使用子字符串功能,但似乎不起作用,请帮忙
Need to extract just the display name (Jund lee in this example) from the above text data in hive, I have tried using substring function but don't seem to work,Please help
推荐答案
使用 regexp_extract 函数和 matching
正则表达式仅捕获 displayName
从您的 title
字段值中获取.
Use regexp_extract function with the matching
regex to capture only the displayName
from your title
field value.
例如:
hive> with tb as(select string('"id":"S-1-98-13474422323-33566802",
"name":"uid=Xzdpr0,ou=people,dc=vm,dc=com","shortName":"XZDPR0",
"displayName":"Jund Lee","emailAddress":"jund.lee@bm.com",
"title":"Leading Product Investor"')title)
select regexp_extract(title,'"displayName":"(.*?)"',1) title from tb;
+-----------+--+
| title |
+-----------+--+
| Jund Lee |
+-----------+--+
这篇关于从配置单元中的文本列中提取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文