【问题标题】:extracting a substring from a text column in hive从 hive 中的文本列中提取子字符串
【发布时间】:2018-11-08 20:58:53
【问题描述】:

我们在名为 title 的列中有文本数据,如下所示

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

需要从 hive 中的上述文本数据中仅提取显示名称(本例中为 Jund lee),我尝试使用 substring 函数但似乎不起作用,请帮助

【问题讨论】:

    标签: hive hql


    【解决方案1】:

    regexp_extract 函数与 matching 正则表达式结合使用,仅从您的 title 字段值中捕获 displayName

    例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 2020-10-06
      • 2021-03-07
      相关资源
      最近更新 更多