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

查看:29
本文介绍了如何为 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.

例如,这里是输入:

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

我如何获得如下输出:

   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 在内的许多 hive 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天全站免登陆