2

I have a relation, reflat1. Below are the output of DESCRIBE and DUMP.

reflat1: {cookie: chararray,tupofstuff: (category: chararray,weight: double,lasttime: long)}
(key1,(613,1.0,1410155702)   
(key2,(iOS,1.0,1410155702)
(key3,(G.M.,1.0,1410155702)

Yes, I notice that the parentheses do not get closed. I have no clue why. Perhaps the reason there are no parentheses is the source of all of my problems.

I want to transform it to a relation (let's call it reflat2) with 4 fields, which would ideally look like:

(key1, 613, 1.0,1410155702)   
(key2, iOS, 1.0,1410155702)
(key3, G.M., 1.0,1410155702)

But my code is NOT working. Below is the relevant bit.

reflat2 = foreach reflat1 {
  GENERATE 
  cookie                  as cookie,
  tupofstuff.(category)   as category,
  tupofstuff.(weight)     as weight,
  tupofstuff.(lasttime)   as lasttime;
};
r1 = LIMIT reflat2 100;
dump r1;

Which leads to the schema I'd expect:

DESCRIBE reflat2
reflat2: {cookie: chararray,category: chararray,weight: double,lasttime: long}

But gives an error on the dump:

Unable to open iterator for alias r1

When I look at the errors on the failed MapReduce jobs, I see:

java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.pig.data.Tuple

Which is weird, because if anything I'm casting a tuple to a string (and a double and a long), not vice versa.

jarfa
  • 549
  • 1
  • 5
  • 12
  • For people who found this post when looking for [ERROR 1066: Unable to open iterator for alias](http://stackoverflow.com/questions/34495085/error-1066-unable-to-open-iterator-for-alias-in-pig-generic-solution) here is a [generic solution](http://stackoverflow.com/a/34495086/983722). – Dennis Jaheruddin Dec 28 '15 at 14:54

1 Answers1

0

Using FLATTEN on TUPLE brings the elements of tuples outside. You should use flatten as below:

reflat2 = foreach reflat1 GENERATE cookie, FLATTEN(tupofstuff);

Hope this helps.

Gaurav Phapale
  • 979
  • 1
  • 8
  • 21
  • Sorry, I've tried that as well and it gives me the exact same error. – jarfa Sep 26 '14 at 15:39
  • @jarfa Could you update the question to include what you tried, and directly make sure that you show a reproducible example with proper inputs? (The inputs you give seem a bit dodgy, so just start with something that has to be correct beyond doubt) – Dennis Jaheruddin Dec 28 '15 at 14:56