如何在PIG或HIVE中添加行号? [英] How can I add row numbers for rows in PIG or HIVE?

查看:219
本文介绍了如何在PIG或HIVE中添加行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apache Pig添加行号时遇到问题。
问题是我有一个STR_ID列,我想为STR_ID中的数据添加一个ROW_NUM列,这是STR_ID的行号。

I have a problem when adding row numbers using Apache Pig. The problem is that I have a STR_ID column and I want to add a ROW_NUM column for the data in STR_ID, which is the row number of the STR_ID.

例如,以下是输入:

For example, here is the input:

STR_ID
------------
3D64B18BC842
BAECEFA8EFB6
346B13E4E240
6D8A9D0249B4
9FD024AA52BA

我如何得到如下输出:

How do I get the output like:

   STR_ID    |   ROW_NUM
----------------------------
3D64B18BC842 |     1
BAECEFA8EFB6 |     2
346B13E4E240 |     3
6D8A9D0249B4 |     4
9FD024AA52BA |     5

使用Pig或Hive的答案是可以接受的。谢谢。

Answers using Pig or Hive are acceptable. Thank you.

推荐答案

Facebook 发布了一些包括NumberRows的配置单元UDF。根据您的配置单元版本(我相信0.8),您可能需要为该类添加一个属性(stateful = true)。

Facebook posted a number of hive UDFs including NumberRows. Depending on your hive version (I believe 0.8) you may need to add an attribute to the class (stateful=true).

这篇关于如何在PIG或HIVE中添加行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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