本文介绍了检查袋子中是否存在某种元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检入piglatin ,如果袋子里有元素吗?
How can I check in piglatin, if a bag contains an element?
示例:在一袋chararray中,如何检查令牌是否存在?
Example : In a bag of chararray, how can I check if a token is present?
推荐答案
在Apache Pig中,您可以使用嵌套在FOREACH 参阅Pig基础知识.这是文档中的示例:A
是B
中的袋子.
In Apache Pig you can use statements nested in FOREACH see Pig Basics. Here is example from the documentation:A
is a bag in B
.
X = FOREACH B {
S = FILTER A BY 'xyz';
GENERATE COUNT (S.$0);
}
您可以使用IsEmpty和?:运算符代替COUNT个
Instead of COUNT you can use IsEmpty and ?: operator
X = FOREACH B {
S = FILTER A BY 'xyz';
GENERATE (IsEmpty(S.$0)) ? 'xyz NOT PRESENT' : 'xyz PRESENT') as present, B;
}
或者只留下装有数据的袋子:
Or only to leave the bags that contain the data:
X = FOREACH B {
S = FILTER A BY 'xyz';
GENERATE B, S;
}
F = FILTER X BY not IsEmpty(S);
R = FOREACH F GENERATE B;
这将避免昂贵的连接本身,因为额外的连接是额外的Map Reduce作业.
This will avoid costly join to itself, as extra joins are extra Map Reduce jobs.
这篇关于检查袋子中是否存在某种元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!