我的数据有3个列值,类似于
1111 some input $in put1
1121 - $in put2
在第一个值和第二个值之间有一个空格分隔符。在第二列和第三列之间$"分隔符。第二行中的第二个值没有提供,所以它只是一个短划线(-(。
我在Hive中的表格声明如下-
CREATE TABLE tab1(someid string,something1 string, something2 string)
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES(
"input.regex"="^(\S+)\s+(\S+\s+\S+)\s+.(.+)$",
"output.format.string"="%1$s %2$s %3$s")
stored as textfile;
我得到的结果是-
1111 Some input $in put1
1121 - $in put2
我期待的是-
1111 Some input in put1
1121 - in put2
如果第二个值只是一个破折号(-(,那么它将作为第二列的值。在最后一列中,我不想要任何分隔符。
我在正则表达式中做错了什么。我喜欢使用相同的S模式正则表达式。请帮忙。
这行得通吗?
"input.regex"="^(\S+)\s+([^$]+)\$(.+)$"
Regex细分:
^ beginning of the string
(\S+) 1 to N non-space characters (capturing)
\s+ 1 to N space characters
([^$]+) 1 to N characters other than a literal "$"
\$ a literal "$"
(.+) 1 to N characters
$ end of the string