我可以在 hadoop - PIG 中对 Map 结构使用“过滤依据"吗? [英] Can I use "filter by' with Map structure in hadoop - PIG?
本文介绍了我可以在 hadoop - PIG 中对 Map 结构使用“过滤依据"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
证明有一个像,,,,
地图文本
[key1#v1]
[key2#v2]
[key3#v3]
然后,如果我尝试找到key2"的值,
then, if I try to find 'value of 'key2'',
A = load ‘map.text’ as (M:map[]);
B = foreach A generate M#'key2';
C = filter B by $0!=''; // to get rid of empty value like (), (), ().
dump C;
还有其他方法可以找到key2吗?仅使用过滤依据".
is there any other way to find key2? with using 'filter by' only.
谢谢你.
推荐答案
不需要GENERATE
一个字段然后在FILTER
中使用它;您可以将其包含在 FILTER
语句中以开始:
There is no need to GENERATE
a field and then use it in a FILTER
; you can include it in the FILTER
statement to begin with:
A = load 'map.text' as (M:map[]);
B = filter A by M#'key2' != '';
dump B;
在您的数据上,这将返回一条记录:
On your data, this returns one record:
([key2#v2])
附带说明,如果空字符串是有效值,您可能更愿意使用的标准是by M#'key2' is not null
.
As a side note, in case empty strings are ever valid values, the criterion you might rather use is by M#'key2' is not null
.
这篇关于我可以在 hadoop - PIG 中对 Map 结构使用“过滤依据"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文