2017-05-04 70 views
0

我用SERDE閱讀與分隔符特定格式數據|我的數據正則表達式在蜂房特定分隔字符串SERDE

一號線可能看起來像:鍵1 =值2 |鍵2 =值| KEY3 =「VA,梅毒」,我創建蜂巢表如下:

CREATE EXTERNAL TABLE(
field1 STRING, 
field2 STRING, 
field3 STRING 
) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' 
WITH SERDEPROPERTIES (
    "input.regex" = "([^\\|]*)\\|([^\\|]*)\\|([^\\|]*)", 
    "output.format.string" = "%1$s %2$s %3$s" 
) 
STORED AS TEXTFILE; 

我需要提取所有值,如果它們存在則忽略所有配額。 結果看起來像一個

value2 value2 va , lues 

我怎樣才能改變我目前的正則表達式的值extractig?

+0

什麼是給定的輸入您的電流輸出結果呢? – horcrux

+0

鍵1 =值2鍵2 =值KEY3 = 「VA,梅毒」 – rmnvnv

+0

所以才改變這個?' 「input.regex」= 「[^ \\ | =] * = \」([^ \\ |] *)\ 「\\?| [^ \\ | =] * = \」([^ \\ |] *)?\ 「\\?| [^ \\ | =] * = \」([^ \\?| ] *)\「?」,' – horcrux

回答

0

我目前可以提供2個選項,他們都不是完美的。
順便說一句,"output.format.string"已過時,並沒有效果。

create external table mytable 
(
    q1   string  
    ,field1  string 
    ,q2   string 
    ,field2  string 
    ,q3   string 
    ,field3  string 
) 
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe' 
with serdeproperties ('input.regex' = '.*?=(?<q1>"?)(.*?)(?:\\k<q1>)\\|.*?=(?<q2>"?)(.*?)(?:\\k<q2>)\\|.*?=(?<q3>"?)(.*?)(?:\\k<q3>)') 
stored as textfile 
; 

select * from mytable 
; 

+----+--------+----+--------+----+-----------+ 
| q1 | field1 | q2 | field2 | q3 | field3 | 
+----+--------+----+--------+----+-----------+ 
| | value2 | | value2 | " | va , lues | 
+----+--------+----+--------+----+-----------+ 
create external table mytable 
(
    field1 string 
    ,field2 string 
    ,field3 string 
) 
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe' 
with serdeproperties ('input.regex' = '.*?=(".*?"|.*?)\\|.*?=(".*?"|.*?)\\|.*?=(".*?"|.*?)') 
stored as textfile 
; 

select * from mytable 
; 

+--------+--------+-------------+ 
| field1 | field2 | field3 | 
+--------+--------+-------------+ 
| value2 | value2 | "va , lues" | 
+--------+--------+-------------+ 
相關問題