检查包中是否存在元素? [英] Check if an element is present in a bag?
本文介绍了检查包中是否存在元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查 piglatin,如果一个包包含一个元素?
How can I check in piglatin, if a bag contains an element?
示例:在一袋字符数组中,如何检查令牌是否存在?
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.
这篇关于检查包中是否存在元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文