user3731877
user3731877

Reputation: 1

HADOOP PIG error related to ORDER dealing with int long

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

Upvotes: 0

Views: 551

Answers (1)

Louise Miller
Louise Miller

Reputation: 3189

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;

Upvotes: 2

Related Questions