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

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

问题描述

我正在生成一个信息包,其大小(包内的元组数)可能会有所不同。从这里,我想要提取第一个元素。我该如何做到这一点? 根据文档,一个包是元组的集合,并且


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

但请注意, b。$ 0 不会为您提供行李中的第一个元组,因为行李没有订购!您将获得组成元组的第一个元素。



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


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?

解决方案

According to the docs, a bag is a collection of tuples and

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.

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.

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天全站免登陆