Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a row number in pig?

I'm using pig for data preparation, and I faced a problem which seems easy but I can't deal with:

for example, I have a column of names

name
------
Alicia
Ana
Benita 
Berta 
Bertha 

then how can I add a row number for each name? the result would be like this:

name    |  id
----------------
Alicia  |  1
Ana     |  2
Benita  |  3
Berta   |  4
Bertha  |  5

Thank you for reading this question!

like image 250
Breakinen Avatar asked Dec 06 '22 16:12

Breakinen


1 Answers

Pig did not have a mechanism to do this when you asked this question. However, Pig 0.11 introduced a RANK operator that can be used for this purpose.

like image 179
cabad Avatar answered Jan 12 '23 14:01

cabad