0

如何在 PIG 中实现以下目标foreach

REL = foreach RELS {
 if ( cnt == 0 )
 limited_result = NULL/Empty;
 else
 limited_result = LIMIT results cnt ;

 generate limited_result.some_field;
}

我不能使用LIMIT,因为它验证 'cnt' 大于 0;我尝试使用 a SPLIT,但显然它不支持在foreach.

4

1 回答 1

2

FILTER在你的 ing 之前怎么样FOREACH

REL = foreach (filter RELS by cnt > 0) {
 limited_result = LIMIT results cnt ;
 generate limited_result.some_field;
}

如果你还需要cnt为0的记录,你可以SPLIT先在为0的时候生成一个空包cnt

split RELS into ZERO if cnt == 0, NONZERO if cnt > 0;

NZ_LIM = foreach NONZERO {
 result = LIMIT results cnt ;
 generate limited_result.some_field;
}
Z_LIM = foreach ZERO generate {} as some_field;

REL = union NZ_LIM, Z_LIM;
于 2013-01-22T18:43:30.253 回答