如何过滤空输出文件?

时间:2016-05-31 10:59:25

标签: apache-pig

这是我的猪脚本。

data = load 's3a://sessionlog/2016-05-28/' using SegmentationDataLoader() as (cookie:chararray,tags_and_pageref:map[]);

tags_data = foreach data generate cookie, tags_and_pageref#'tags' as score_tag_bag;

flattened_data = FOREACH tags_data GENERATE cookie, FLATTEN(score_tag_bag) as score_tag;

converted_flattened_data = FOREACH flattened_data GENERATE cookie, (long)score_tag#'score' as score, score_tag#'tag' as tag;

-- dump converted_flattened_data;

-- tuple_data = FOREACH flattened_data GENERATE cookie, TOTUPLE(tags) as tag_tuple;

-- splited_data = FOREACH flattened_data GENERATE cookie, TOKENIZE(tags) as score_tags:bag{t1:(),t2:()};

grouped_data = group converted_flattened_data by (cookie,tag);

acc_data = foreach grouped_data generate group.cookie as cookie, group.tag as tag,SUM(converted_flattened_data.score) as score;

pageref_data = foreach data generate cookie, tags_and_pageref#'pageref' as pageref_bag;

flattened_pageref_data = FOREACH pageref_data GENERATE cookie, FLATTEN(pageref_bag) as score_tag;

filtered_data = FILTER  flattened_pageref_data BY score_tag is not null and not IsEmpty(score_tag);

store acc_data into 'segmentation/2016-05-28/4' using PigStorage(',');

store filtered_data into 'pagerefdata/2016-05-28/4' using PigStorage(',');

然而,pagerefdata的输出都是空文件。如何过滤它,因为它们都是空的,我不想要任何输出。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我不确定我在这里完全理解你的问题,但是从底部开始的3行你似乎试图通过测试null来过滤掉空的。您是否尝试过以下操作?:

FILTER flattened_pageref_data BY SIZE(TRIM(score_tag)) == 0;