Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Generating schema in FOREACH and then group by causing java.lang.ClassCastException: org.apache.pig.data.DataByteArray

Generating schema in FOREACH and then group by causing java.lang.ClassCastException: org.apache.pig.data.DataByteArray

loaded file with flights data from practice exam : a = load 'file' using PigStorage(',');

generated schema using foreach: b = foreach a generate $6 as art:int, $17 as dest:chararray;

simple group by: c = group b by art; or dest fails.

dump c;

ERROR: java.lang.ClassCastException: org.apache.pig.data.DataByteArray cannot be cast to java.lang.Integer

or

ERROR: java.lang.ClassCastException: org.apache.pig.data.DataByteArray cannot be cast to java.lang.String ?????

2 REPLIES 2
Highlighted

Re: Generating schema in FOREACH and then group by causing java.lang.ClassCastException: org.apache.pig.data.DataByteArray

Expert Contributor

You can not convert chararray to int implicitly in statements other than load statement.

e.g.

a = load 'a.txt' using PigStorage('\t') as (a:int, b:chararray);
Highlighted

Re: Generating schema in FOREACH and then group by causing java.lang.ClassCastException: org.apache.pig.data.DataByteArray

You can also EXPLICITLY CAST after the load as:

a = load 'a.txt' using PigStorage('\t'); 
b = foreach a generate (int)$6 as art:int, (chararray)$17 as dest:chararray;
Don't have an account?
Coming from Hortonworks? Activate your account here