Rafael
Rafael

Reputation: 124

Extract element of a tuple in a bag on PIG

I'm a Java dev that have to turn off the fire on a PIG script but I'm having an annoying issue with a bag.

I got this bag of a result of a grouping:

{(GET_DIRECTIONS),(GET_DIRECTIONS)}

I only need GET_DIRECTIONS, it doesn't matter the position in the bag because my worst scenario is a bag of three elements with exactly same values (I know, we got a design problem but I cannot do a lot to solve it)

So the first thing I tried was(without reading the apache doc):

$1.state[0] as state

But it failed as there is no such thing as an index in the bag, so reading the doc I tried something like:

$1.state.$0 as state

With no failures but still getting {(GET_DIRECTIONS),(GET_DIRECTIONS)}

Is there a simple way to extract the content of the tuple in the bag?

Upvotes: 0

Views: 487

Answers (1)

Rafael
Rafael

Reputation: 124

I got it, flatten works.

FLATTEN($1.state) as state

Upvotes: 0

Related Questions