2017-05-04 95 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" | 
+--------+--------+-------------+