[英]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
bu1
、 bu2
、 bu3
提取到一個名為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.