如何在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;
我尝试使用SPLIT
,但foreach
显然不支持。{/ p>
答案 0 :(得分:2)
FILTER
之前FOREACH
怎么样?
REL = foreach (filter RELS by cnt > 0) {
limited_result = LIMIT results cnt ;
generate limited_result.some_field;
}
如果您仍需要cnt
为0的记录,则可以先SPLIT
,然后在cnt
为0时生成一个空包:
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;