如何在猪中指定封闭?
How to specify enclosed by in pig?
我正在写一个 pig 脚本,我的数据是 space 分隔的,在某些列中,它们之间有 space,但它用下面的双引号 (") 括起来是样本看起来很像我拥有的数据:
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
我正在尝试实现 a 到 g 列,其中 f f1 和 f2 位于 f 之下,但我得到两个额外的列 f1 和 f2,它们应该位于 f 列中
a = load 'file.txt' Using PigStorage(' ');
我怎样才能在猪中做到这一点?
更新数据
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
a1 b1 c1 d1 e1 "fgn f1 f11 f12" g1
a1 b1 c1 d1 e1 f1 g1
你可以使用 REGEX 解决这个问题,你可以试试下面的方法吗?
输入:
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
a1 b1 c1 d1 e1 "fgn f1 f11 f12" g1
a1 b1 c1 d1 e1 f1 g1
PigScript:
A = LOAD 'input' AS (line:chararray);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(line,'(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+"?([A-Za-z0-9\s]+)"?\s+(\w+)')) AS (col1,col2,col3,col4,col5,col6,col7);
DUMP B;
输出:
(a,b,c,d,e,f f1 f2,g)
(a1,b1,c1,d1,e1,f1 f11 f12,g1)
(a1,b1,c1,d1,e1,fgn f1 f11 f12,g1)
(a1,b1,c1,d1,e1,f1,g1)
现在 col6
变量将把值 "f f1 f2"
和 "f1 f11 f12"
存储为一个单元。
我正在写一个 pig 脚本,我的数据是 space 分隔的,在某些列中,它们之间有 space,但它用下面的双引号 (") 括起来是样本看起来很像我拥有的数据:
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
我正在尝试实现 a 到 g 列,其中 f f1 和 f2 位于 f 之下,但我得到两个额外的列 f1 和 f2,它们应该位于 f 列中
a = load 'file.txt' Using PigStorage(' ');
我怎样才能在猪中做到这一点?
更新数据
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
a1 b1 c1 d1 e1 "fgn f1 f11 f12" g1
a1 b1 c1 d1 e1 f1 g1
你可以使用 REGEX 解决这个问题,你可以试试下面的方法吗?
输入:
a b c d e "f f1 f2" g
a1 b1 c1 d1 e1 "f1 f11 f12" g1
a1 b1 c1 d1 e1 "fgn f1 f11 f12" g1
a1 b1 c1 d1 e1 f1 g1
PigScript:
A = LOAD 'input' AS (line:chararray);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(line,'(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+"?([A-Za-z0-9\s]+)"?\s+(\w+)')) AS (col1,col2,col3,col4,col5,col6,col7);
DUMP B;
输出:
(a,b,c,d,e,f f1 f2,g)
(a1,b1,c1,d1,e1,f1 f11 f12,g1)
(a1,b1,c1,d1,e1,fgn f1 f11 f12,g1)
(a1,b1,c1,d1,e1,f1,g1)
现在 col6
变量将把值 "f f1 f2"
和 "f1 f11 f12"
存储为一个单元。