如何从 PIG 中生成的包(其大小可能会有所不同)中提取第一个元组? [英] How do I extract the first tuple from a generated bag (whose size might vary) in PIG?

查看:18
本文介绍了如何从 PIG 中生成的包(其大小可能会有所不同)中提取第一个元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个信息包",其大小(包内的元组数)可能会有所不同.由此,我想即时提取第一个元素.我该怎么做?

I am generating a 'bag' of information whose size (number of tuples inside the the bag) might vary. From this, I want to extract the first element on the fly. How do I do this?

推荐答案

根据 文档,包是元组和

包解引用可以通过名称 (bag.field_name) 或位置 (bag.$0) 来完成.如果取消引用一组字段(bag.(name1, name2) 或 bag.($0, $1)),则表达式表示由指定字段组成的包.

Bag dereferencing can be done by name (bag.field_name) or position (bag.$0). If a set of fields are dereferenced (bag.(name1, name2) or bag.($0, $1)), the expression represents a bag composed of the specified fields.

但是要小心,b.$0 不会给你包中的第一个元组,因为包不是有序的!您将获得组成元组的第一个元素.

But be careful, b.$0 doesn't give you the first tuple in the bag, because bags aren't ordered! You'll get the first elements of the constituent tuples.

您需要将包转换为有序结构,或者使用 UDF 更好.你也应该不接受这个答案(所以我可以删除它)并接受 Guarev 的,他有一个 UDF 的链接.

You will need to either convert the bag to an ordered structure, or better, use a UDF. You should also unaccept this answer (so I can delete it) and accept Guarev's instead, who has a link to a UDF.

这篇关于如何从 PIG 中生成的包(其大小可能会有所不同)中提取第一个元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆