extracting a substring from a text column in hive

喜你入骨 提交于 2021-02-08 10:04:42

问题


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"

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


回答1:


Use regexp_extract function with the matching regex to capture only the displayName from your title field value.

Ex:

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  |
+-----------+--+


来源:https://stackoverflow.com/questions/53216034/extracting-a-substring-from-a-text-column-in-hive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!