You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by sonia gehlot <so...@gmail.com> on 2012/06/08 00:19:01 UTC

Can I check if the field is integer or not

Hi Guys,

Is there is any way in Pig to check either the field is integer or not.

I have a pig script with a field coming as string and I am expecting it to
have always integer value, but due to some data nuisance field might
contain string and in such cases when I cast it to integer it throughs an
error (can't convert string into integer). Is there is any way where I can
use case statement say if the field integer then cast it to integer else
put '-1'.

Thanks for any help,
Sonia

Re: Can I check if the field is integer or not

Posted by sonia gehlot <so...@gmail.com>.
Great thanks Prashant!

On Thu, Jun 7, 2012 at 3:28 PM, Prashant Kommireddi <pr...@gmail.com>wrote:

> Hi Sonia,
>
> We checked in UDFs for this into trunk, and will be a part of a future
> release (0.11). Please take a look at
> https://issues.apache.org/jira/browse/PIG-2443 to apply the patch to your
> version, or just to use it externally.
>
> In addition, this patch also includes IsFloat, IsLong and IsDouble.
>
> Thanks,
> Prashant
>
> On Thu, Jun 7, 2012 at 3:19 PM, sonia gehlot <so...@gmail.com>
> wrote:
>
> > Hi Guys,
> >
> > Is there is any way in Pig to check either the field is integer or not.
> >
> > I have a pig script with a field coming as string and I am expecting it
> to
> > have always integer value, but due to some data nuisance field might
> > contain string and in such cases when I cast it to integer it throughs an
> > error (can't convert string into integer). Is there is any way where I
> can
> > use case statement say if the field integer then cast it to integer else
> > put '-1'.
> >
> > Thanks for any help,
> > Sonia
> >
>

Re: Can I check if the field is integer or not

Posted by Prashant Kommireddi <pr...@gmail.com>.
Hi Sonia,

We checked in UDFs for this into trunk, and will be a part of a future
release (0.11). Please take a look at
https://issues.apache.org/jira/browse/PIG-2443 to apply the patch to your
version, or just to use it externally.

In addition, this patch also includes IsFloat, IsLong and IsDouble.

Thanks,
Prashant

On Thu, Jun 7, 2012 at 3:19 PM, sonia gehlot <so...@gmail.com> wrote:

> Hi Guys,
>
> Is there is any way in Pig to check either the field is integer or not.
>
> I have a pig script with a field coming as string and I am expecting it to
> have always integer value, but due to some data nuisance field might
> contain string and in such cases when I cast it to integer it throughs an
> error (can't convert string into integer). Is there is any way where I can
> use case statement say if the field integer then cast it to integer else
> put '-1'.
>
> Thanks for any help,
> Sonia
>

Re: Can I check if the field is integer or not

Posted by Kris Coward <kr...@melon.org>.
And both of these only cover positive/unsigned integers, and allowing
for negatives you'd want '-?[0-9]+'

On Fri, Jun 08, 2012 at 03:20:01PM +0000, Steve Bernstein wrote:
> ...for a one digit integer, or '[0-9]+' an integer of one or more digits. 
> ________________________________________
> From: Jagat Singh [jagatsingh@gmail.com]
> Sent: Thursday, June 07, 2012 7:08 PM
> To: user@pig.apache.org
> Subject: Re: Can I check if the field is integer or not
> 
> You can use regular expression
> 
> Field matches '[0-9]'
> 
> -----------
> Sent from Mobile , short and crisp.
> On 08-Jun-2012 3:49 AM, "sonia gehlot" <so...@gmail.com> wrote:
> 
> > Hi Guys,
> >
> > Is there is any way in Pig to check either the field is integer or not.
> >
> > I have a pig script with a field coming as string and I am expecting it to
> > have always integer value, but due to some data nuisance field might
> > contain string and in such cases when I cast it to integer it throughs an
> > error (can't convert string into integer). Is there is any way where I can
> > use case statement say if the field integer then cast it to integer else
> > put '-1'.
> >
> > Thanks for any help,
> > Sonia
> >

-- 
Kris Coward					http://unripe.melon.org/
GPG Fingerprint: 2BF3 957D 310A FEEC 4733  830E 21A4 05C7 1FEB 12B3

RE: Can I check if the field is integer or not

Posted by Steve Bernstein <St...@deem.com>.
...for a one digit integer, or '[0-9]+' an integer of one or more digits. 
________________________________________
From: Jagat Singh [jagatsingh@gmail.com]
Sent: Thursday, June 07, 2012 7:08 PM
To: user@pig.apache.org
Subject: Re: Can I check if the field is integer or not

You can use regular expression

Field matches '[0-9]'

-----------
Sent from Mobile , short and crisp.
On 08-Jun-2012 3:49 AM, "sonia gehlot" <so...@gmail.com> wrote:

> Hi Guys,
>
> Is there is any way in Pig to check either the field is integer or not.
>
> I have a pig script with a field coming as string and I am expecting it to
> have always integer value, but due to some data nuisance field might
> contain string and in such cases when I cast it to integer it throughs an
> error (can't convert string into integer). Is there is any way where I can
> use case statement say if the field integer then cast it to integer else
> put '-1'.
>
> Thanks for any help,
> Sonia
>

Re: Can I check if the field is integer or not

Posted by Jagat Singh <ja...@gmail.com>.
You can use regular expression

Field matches '[0-9]'

-----------
Sent from Mobile , short and crisp.
On 08-Jun-2012 3:49 AM, "sonia gehlot" <so...@gmail.com> wrote:

> Hi Guys,
>
> Is there is any way in Pig to check either the field is integer or not.
>
> I have a pig script with a field coming as string and I am expecting it to
> have always integer value, but due to some data nuisance field might
> contain string and in such cases when I cast it to integer it throughs an
> error (can't convert string into integer). Is there is any way where I can
> use case statement say if the field integer then cast it to integer else
> put '-1'.
>
> Thanks for any help,
> Sonia
>