deepujain
deepujain

Reputation: 687

How to read data from data bag within a PIG script

I have a databag which is the following format {([ChannelName#{ (bigXML,[])} ])}

I have a UDF that emits the above bag.

Now i need to invoke another UDF by passing the only tuple within the DataBag against a given Channel from the Map.

Assuming there was not data bag and a tuple as ([ChannelName#{ (bigXML,[])} ]) I can access the data using $0.$0#'StdOutChannel' Now with the tuple inside a bag {([ChannelName#{ (bigXML,[])} ])} If i do $0.$0.$0#'StdOutChannel' (Prepend $0), i get the following error ERROR 1052: Cannot cast bag with schema bag({bytearray}) to map

How can I access data within a data bag?

Upvotes: 2

Views: 6176

Answers (1)

PP.
PP.

Reputation: 10864

Try to break this problem down a little.

Let's say you get your inner bag:

MYBAG = $0.$0#'StdOutChannel';

First, can you ILLUSTRATE or DUMP this?

What can you do with this bag? Usually FOREACH over the tuples inside.

A = FOREACH MYBAG {
    GENERATE $0 AS MyCharArray, $1 AS MyMap
};

ILLUSTRATE A; -- or if this doesn't work
DUMP A;

Can you try this interactively and maybe edit your question a little more with some details as a result of you trying these things.

Some editing hints for StackOverflow:

  • put backticks around your code (`ILLUSTRATE`)
  • indent code blocks by 4 spaces on each line

Upvotes: 2

Related Questions