Support Questions

Find answers, ask questions, and share your expertise

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

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);

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;