0

here is the partial code (omitted code before this portion is already tested)

   data3 = FOREACH data2 GENERATE group, SUM(data1.cpc) as cost:int;
   data4 = ORDER data3 BY cost ASC;
   DESCRIBE data4;

this has no problem with result:

data4: {group: chararray,cost: int}

however, if I change the

DESCRIBE data4

to

DUMP data4

, it will cause error:

2014-06-11 17:22:26,525 ERROR org.apache.pig.tools.pigstats.SimplePigStats:
ERROR: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.L
ong cannot be cast to java.lang.Integer

2014-06-11 17:22:26,525 ERROR org.apache.pig.tools.pigstats.PigStatsUtil: 1
map reduce job(s) failed!

2014-06-11 17:22:26,573 ERROR org.apache.pig.tools.grunt.Grunt: ERROR 1066:
Unable to open iterator for alias data4. Backend error : java.lang.RuntimeEx
ception: java.lang.ClassCastException: java.lang.Long cannot be cast to java
.lang.Integer

I checked the data for cost field, the value each is within int range, however if I change

as cost:int

to

as cost:long

, error gone

I just can not understand how the long type is involved here

Thanks

  • What is the datatype of `cpc` from `data1` ? – o-90 Jun 13 '14 at 20:53
  • 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:48

1 Answers1

2

It doesnt matter that the value for cost field is within int range. That might work if it was casting primitive int to long. But in Pig, defining in the schema a field as cost:int is defining it as the object java.lang.Integer, and that cannot be cast to a java.lang.Long

e.g the following doesnt even compile in java :

    Integer myInt = new Integer(23);
    Long myLong = (Long) myInt;

and this causes a ClassCastException :

    Integer myInt = new Integer(23);

    Object myObject = (Object) myInt;

    Long myLong = (Long) myObject;
Louise Miller
  • 3,069
  • 2
  • 12
  • 13