Enigma
Enigma

Reputation: 11

how to extract single element from a bag in pig?

My pig statement generates the following output:

({(10)},5201)
({(20),(20),(20)},3334)
({(30),(30),(30),(30)},4632)
({(40),(40)},3101)
({(50),(50)},3801)
({(60),(60),(60)},3959)

But I want to store above output as below in pig:

(10,5201)
(20,3334)
(30,4632)
(40,3101)
(50,3801)
(60,3959)

Is there any way to extract the very first element from bag in pig?

Upvotes: 0

Views: 100

Answers (1)

pauljcg
pauljcg

Reputation: 193

Use the Datafu UDF FirstTupleFromBag to achieve exactly this!

Upvotes: 1

Related Questions