

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
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 <[EMAIL PROTECTED]>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 [EMAIL PROTECTED] going forward.*

Re: Class Cast Exception
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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>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 > [EMAIL PROTECTED] going forward.*

