You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Viswanathan K S <vi...@gmail.com> on 2012/09/28 15:03:31 UTC

Class Cast Exception

Hi,


I am a newbie in Pig.

Tried extracting a piece of string from a given text using substring and
made the extracted string as double.

Then performing some mathematical functions on the extracted string throws
me an exception.

Ex :

Data : abc/123.34/-234.45,xxxx
          def/122.45/-445.65,xxxx
          ghi/223.45/-555.55,xxx

Considering ‘ ,’  as the delimiter.

a = load  'data' using PigStorage(‘,’) as (f1,f2);



B = foreach a generate SUBSTRING(f1,4,10) as d1:double;



Now if I compute some mathematical operation on d1, getting a
ClassCastException Error :



“java.lang.ClassCastException : java.lang.String cannot be cast to
java.long.Double”



Kindly help regarding the same.


Thanks and Regards,

ksviswa

Re: Class Cast Exception

Posted by Lauren Blau <la...@digitalreasoning.com>.
or what about casting it when you create it like:
(double) SUBSTRING(f1,4,10) as d1:double;

On Fri, Sep 28, 2012 at 11:31 AM, Bill Graham <bi...@gmail.com> wrote:
> Try generating the substring as a chararray and then casting it to int in
> another FOREACH.
>
> On Fri, Sep 28, 2012 at 6:03 AM, Viswanathan K S <vi...@gmail.com>wrote:
>
>> Hi,
>>
>>
>> I am a newbie in Pig.
>>
>> Tried extracting a piece of string from a given text using substring and
>> made the extracted string as double.
>>
>> Then performing some mathematical functions on the extracted string throws
>> me an exception.
>>
>> Ex :
>>
>> Data : abc/123.34/-234.45,xxxx
>>           def/122.45/-445.65,xxxx
>>           ghi/223.45/-555.55,xxx
>>
>> Considering ‘ ,’  as the delimiter.
>>
>> a = load  'data' using PigStorage(‘,’) as (f1,f2);
>>
>>
>>
>> B = foreach a generate SUBSTRING(f1,4,10) as d1:double;
>>
>>
>>
>> Now if I compute some mathematical operation on d1, getting a
>> ClassCastException Error :
>>
>>
>>
>> “java.lang.ClassCastException : java.lang.String cannot be cast to
>> java.long.Double”
>>
>>
>>
>> Kindly help regarding the same.
>>
>>
>> Thanks and Regards,
>>
>> ksviswa
>>
>
>
>
> --
> *Note that I'm no longer using my Yahoo! email address. Please email me at
> billgraham@gmail.com going forward.*

Re: Class Cast Exception

Posted by Bill Graham <bi...@gmail.com>.
Try generating the substring as a chararray and then casting it to int in
another FOREACH.

On Fri, Sep 28, 2012 at 6:03 AM, Viswanathan K S <vi...@gmail.com>wrote:

> Hi,
>
>
> I am a newbie in Pig.
>
> Tried extracting a piece of string from a given text using substring and
> made the extracted string as double.
>
> Then performing some mathematical functions on the extracted string throws
> me an exception.
>
> Ex :
>
> Data : abc/123.34/-234.45,xxxx
>           def/122.45/-445.65,xxxx
>           ghi/223.45/-555.55,xxx
>
> Considering ‘ ,’  as the delimiter.
>
> a = load  'data' using PigStorage(‘,’) as (f1,f2);
>
>
>
> B = foreach a generate SUBSTRING(f1,4,10) as d1:double;
>
>
>
> Now if I compute some mathematical operation on d1, getting a
> ClassCastException Error :
>
>
>
> “java.lang.ClassCastException : java.lang.String cannot be cast to
> java.long.Double”
>
>
>
> Kindly help regarding the same.
>
>
> Thanks and Regards,
>
> ksviswa
>



-- 
*Note that I'm no longer using my Yahoo! email address. Please email me at
billgraham@gmail.com going forward.*