簡體   English   中英

需要 Hive 相當於 oracle 的 regexp_extract 來提取模式之間的文本

[英]Need Hive equivalent of oracle's regexp_extract to extract text between patterns

我的數據如下所示:

bizunit
nam-bu1-us-credit
nam-bu2-us-debit
latam-bu3-mx-debit

現在我想將nam & latam提取到一個名為region的單獨列中, bu2 bu1bu2bu3提取到一個名為business unit的單獨列中,並將us , mx提取到一個名為country的單獨列中。

我將使用什么 hive 函數和 SQL? 請分享一個示例 hive SQL 將上述數據拆分為 3 列以按上述方式提取。

CREATE TABLE myTably(
  myText string
  )
INSERT INTO TABLE concat_test VALUES 
  ('nam-bu1-us-credit'), 
  ('nam-bu2-us-debit'), 
  ('latam-bu3-mx-debit');

這是提取地區、業務單位和國家的查詢

select 
regexp_extract(myText, '([^-]+)-([^-]+)-([^-]+)-', 1),
regexp_extract(myText, '([^-]+)-([^-]+)-([^-]+)-', 2),
regexp_extract(myText, '([^-]+)-([^-]+)-([^-]+)-', 3) from MyTable

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM