ProggerJoe
ProggerJoe

Reputation: 97

PIGLatin Flattening multiple columns

Sorry folks I just started using PIG a few days ago. I have no Idea how to fix this problem. Any help would be really appreciated.

is there a way to make this code independent from the number of columns? As I am trying to put it all in one column but each cell as a single cell.

    C= FOREACH A GENERATE FLATTEN ($1);
    D= FOREACH A GENERATE FLATTEN ($2);
    E= FOREACH A GENERATE FLATTEN ($3);
    F= FOREACH A GENERATE FLATTEN ($4);
    G= FOREACH A GENERATE FLATTEN ($5);

X= UNION C,D,E,F,G;

DESCRIBE X;
DUMP X;

Cheers Joe

Upvotes: 1

Views: 1181

Answers (2)

Gubi
Gubi

Reputation: 415

You can try

FOREACH A
GENERATE FLATTEN(TOBAG($1, $2, $3, $4, $5));


FOREACH A
GENERATE FLATTEN(TOBAG(*));

Upvotes: 0

Rengasamy
Rengasamy

Reputation: 1043

I think there is no solution for this instead of using Foreach in Pig as the above you mentioned. In UDF also you need to store each column value in separate variables.

Upvotes: 1

Related Questions