将 Pig 中的字符串拆分为一列,然后将其存储在一行中

Splitting a string in Pig in a column and then storing it in a row

我有一个包含 4 列数据但有 250000 行的 csv 文件。

A          B      C     D               
Tom        1      x    Blah Blah Blah
Bob        2      y    Blah <p> Blah
Jane       3      z    Blah, &p *£
Harry      4      a    Blah "p" Blah

在第 4 列中,我有一个包含各种字符的字符串,一些代码,一些特殊字符,一些文本。

我想将 D 中的每个单词与 A 中的内容组合起来,并将其存储在一个新行中,即

Tom Blah
Tom Blah
Tom Blah
Bob Blah
Bob <p>
Bob Blah
Jane Blah,
Jane &p
Jane *£
Harry Blah
Harry "p"
Harry Blah

您将不得不使用 STRSPLIT and TOBAG to convert the value in the 4th column of your data set to first split the data and convert it into rows.Finally CONCAT 带有“ ”的结果 2 列。

猪文

A = LOAD 'test6.txt' USING PigStorage('\t') AS (f1:chararray,f2:chararray,f3:chararray,f4:chararray);
B = FOREACH A GENERATE f1,FLATTEN(STRSPLIT(f4,' '));
C = FOREACH B GENERATE [=10=],FLATTEN(TOBAG(,,));
D = FOREACH C GENERATE CONCAT([=10=],CONCAT(' ',));
DUMP D;;

输出