0

我有以下数据集:

1,11,ab;cd;200

2,22,pq;rs

我想要这个输出:

1,11,ab

1,11,cd

1,11,200

2,22,pq

2,22,rs

如何在不使用任何 udf 的情况下在 Pig 中完成?

4

2 回答 2

0

你可以这样做:

A = load '....' using PigStorage(',') as (x,y,data : chararray);
SPLT = foreach A generate x, y, FLATTEN(STRSPLIT(data,';'));
X_tmp = foreach SPLT generate $0 as x, $1 as y, FLATTEN(TOBAG($2..$20)) as term; -- pivots the row
X = filter X_tmp by term is not null; -- this removes the extra bag rows when title was split in less than 20 terms

假设数据字符串中的元素不会超过 20 个。如果你有更多,而不是增加它。

于 2012-10-22T17:38:57.670 回答
0

尝试这个

    A = load 'data' using PigStorage(',') as (x,y,data:chararray);
    SPLT = foreach A generate x, y, FLATTEN(STRSPLIT(data,';',3)) as (a,b,c);
    grp = group SPLT by (x,y);
    res = foreach grp generate group, FLATTEN(SPLT);
    out = foreach res generate FLATTEN(group), FLATTEN(TOBAG(SPLT::a, SPLT::b, strong textSPLT::c)) as val;
    dump out;
于 2017-01-27T00:27:03.117 回答