Can I use "filter by' with Map structure in hadoop - PIG?

*爱你&永不变心* 提交于 2020-01-05 04:18:14

问题


provied that there's a Map like,,,

map.text

[key1#v1]
[key2#v2]
[key3#v3]

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;

is there any other way to find key2? with using 'filter by' only.

thxs ya.


回答1:


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])

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.



来源:https://stackoverflow.com/questions/18556902/can-i-use-filter-by-with-map-structure-in-hadoop-pig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!