ID / counter generation for foreach in lead latin

I want some unique identifier / pen_number / counter to be generated / added to my foreach construct, iterating through the records. Is there a way to do this without writing UDF?

B = foreach A generate a_unique_id, field1, ... etc

How can I implement this "a_unique_id"?

Thanks!

+6
source share
2 answers

If you use pigs 0.11 or later, then the RANK statement is exactly what you are looking for. For instance.

 DUMP A; (foo,19) (foo,19) (foo,7) (bar,90) (etc.,0) B = RANK A ; DUMP B ; (1,foo,19) (2,foo,19) (3,foo,7) (4,bar,90) (5,etc.,0) 
+4
source

There is no built-in UUID function in the main pig distribution or piggy bank. Unfortunately, I think your only option would be to write UDF.

There is a standard standard way to create UUIDs , and there is Java code that you can use to create your UDF.

Is there a specific reason why you do not want to write UDF?

+1
source

Source: https://habr.com/ru/post/898531/


All Articles