我可以在hadoop-PIG中对Map结构使用"filter by"吗? [英] Can I use "filter by' with Map structure in hadoop - PIG?
本文介绍了我可以在hadoop-PIG中对Map结构使用"filter by"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
证明其中有一个地图,
map.text
[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结构使用"filter by"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文