Hmm, I apologize. I am now unable to find the situation where I saw an
exception trying to cast a long to a double.

My script basically takes a bunch of results of COUNT's and divide them to
get a floating point number. But now that you guys responded, I cannot find
a version of my script or a version of pig.jar that produces those
results...

In fact, the single cast

"generate (double) x / y as div"

works for me now where x and y are int and long.

Sigh... one more point for the haunted colo I guess.




On Thu, Jul 15, 2010 at 3:49 PM, Miguel Rios <[email protected]> wrote:

> (double)c/(double)v works.
>
> data = load '/home/miguel/test.txt' as (a:int,b:int);
> dump data;
> (1,2)
> (2,1)
> calc = foreach data generate (double)a/(double)b;
> dump calc;
> (0.5)
> (2.0)
>
> On Thu, Jul 15, 2010 at 3:39 PM, Brian Adams <[email protected]>
> wrote:
>
> > ((double)c/(double)v) perhaps?
> >
> > -----Original Message-----
> > From: hc busy [mailto:[email protected]]
> > Sent: Thursday, July 15, 2010 6:36 PM
> > To: [email protected]
> > Subject: how do I convert int to double in PigLatin?
> >
> > if my table is:
> >
> > t = load 'data' as (v:int, c:int);
> >
> > and I want to do
> >
> > u = foreach t generate c/v as cov;
> >
> > how do I get fraction out of this? because
> >
> > u = foreach t generate (double)c / v;
> >
> > crashes with a casting error for me, do I write an UDF?
> >
>
>
>
> --
> Miguel Ríos-Berríos
> Computer Science Graduate Student
> Graduate Research Assistant
> Human Computer Interaction Lab
> University of Maryland, College Park
> [email protected]
>

Reply via email to