You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Something Something <ma...@gmail.com> on 2013/09/04 07:50:32 UTC

COALESCE UDF?

Is there a UDF in Piggybank (or somewhere) that will mimic functionality of
the COALESCE function in MySQL:

http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php

I know it will be very (very) easy to write this, but just don't want to
create one if one already exists.  I looked but couldn't find one.

Please let me know.  Thanks.

Re: COALESCE UDF?

Posted by Russell Jurney <ru...@gmail.com>.
On the other hand, if you use a java UDF, consider contributing it.

Sent from my iPhone

On Sep 4, 2013, at 9:10 AM, Serega Sheypak <se...@gmail.com> wrote:

> Use simple jython UDF. Its 3 lines of code
> 04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com> написал:
> 
>> For my two cents' worth I agree, it's nicer to have coalesce than the
>> conditional operator.
>> 
>> On Sep 4, 2013, at 8:50 AM, Something Something <ma...@gmail.com>
>> wrote:
>> 
>>> What if you've 10 fields?
>>> 
>>> 
>>> On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <metaruslan@gmail.com
>>> wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I think you could mimic it with an expression like this:
>>>> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
>>>> field2) : field1);
>>>> 
>>>> Hope that helps,
>>>> Ruslan
>>>> 
>>>> 
>>>> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
>>>> mailinglists19@gmail.com> wrote:
>>>> 
>>>>> Is there a UDF in Piggybank (or somewhere) that will mimic
>> functionality
>>>> of
>>>>> the COALESCE function in MySQL:
>> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
>>>>> 
>>>>> I know it will be very (very) easy to write this, but just don't want
>> to
>>>>> create one if one already exists.  I looked but couldn't find one.
>>>>> 
>>>>> Please let me know.  Thanks.
>> 

Re: COALESCE UDF?

Posted by Serega Sheypak <se...@gmail.com>.
def coalesce(*arg):
    for el in arg:
        if el is not None:
            return el
    return None


2013/9/4 Russell Jurney <ru...@gmail.com>

> Suggest if OP is aware of jython implementation, his question is resolved.
>
> Sent from my iPhone
>
> On Sep 4, 2013, at 9:40 AM, Something Something <ma...@gmail.com>
> wrote:
>
> > Serega - I think you missed this line:
> >
> > "....I know it will be very (very) easy to write this, but just don't
> want
> > to create one if one already exists....."
> >
> > There's a saying, don't code something that's already been coded!  "Code
> > Reuse" for the win!
> >
> > Anyway, seems like the simple answer is "NO, this doesn't exist in
> > Piggybank".  Thanks.
> >
> >
> >
> > On Wed, Sep 4, 2013 at 9:10 AM, Serega Sheypak <serega.sheypak@gmail.com
> >wrote:
> >
> >> Use simple jython UDF. Its 3 lines of code
> >> 04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com>
> написал:
> >>
> >>> For my two cents' worth I agree, it's nicer to have coalesce than the
> >>> conditional operator.
> >>>
> >>> On Sep 4, 2013, at 8:50 AM, Something Something <
> >> mailinglists19@gmail.com>
> >>> wrote:
> >>>
> >>>> What if you've 10 fields?
> >>>>
> >>>>
> >>>> On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <
> metaruslan@gmail.com
> >>>> wrote:
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> I think you could mimic it with an expression like this:
> >>>>> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
> >>>>> field2) : field1);
> >>>>>
> >>>>> Hope that helps,
> >>>>> Ruslan
> >>>>>
> >>>>>
> >>>>> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
> >>>>> mailinglists19@gmail.com> wrote:
> >>>>>
> >>>>>> Is there a UDF in Piggybank (or somewhere) that will mimic
> >>> functionality
> >>>>> of
> >>>>>> the COALESCE function in MySQL:
> >>
> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
> >>>>>>
> >>>>>> I know it will be very (very) easy to write this, but just don't
> want
> >>> to
> >>>>>> create one if one already exists.  I looked but couldn't find one.
> >>>>>>
> >>>>>> Please let me know.  Thanks.
> >>
>

Re: COALESCE UDF?

Posted by Russell Jurney <ru...@gmail.com>.
Suggest if OP is aware of jython implementation, his question is resolved.

Sent from my iPhone

On Sep 4, 2013, at 9:40 AM, Something Something <ma...@gmail.com> wrote:

> Serega - I think you missed this line:
> 
> "....I know it will be very (very) easy to write this, but just don't want
> to create one if one already exists....."
> 
> There's a saying, don't code something that's already been coded!  "Code
> Reuse" for the win!
> 
> Anyway, seems like the simple answer is "NO, this doesn't exist in
> Piggybank".  Thanks.
> 
> 
> 
> On Wed, Sep 4, 2013 at 9:10 AM, Serega Sheypak <se...@gmail.com>wrote:
> 
>> Use simple jython UDF. Its 3 lines of code
>> 04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com> написал:
>> 
>>> For my two cents' worth I agree, it's nicer to have coalesce than the
>>> conditional operator.
>>> 
>>> On Sep 4, 2013, at 8:50 AM, Something Something <
>> mailinglists19@gmail.com>
>>> wrote:
>>> 
>>>> What if you've 10 fields?
>>>> 
>>>> 
>>>> On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <metaruslan@gmail.com
>>>> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I think you could mimic it with an expression like this:
>>>>> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
>>>>> field2) : field1);
>>>>> 
>>>>> Hope that helps,
>>>>> Ruslan
>>>>> 
>>>>> 
>>>>> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
>>>>> mailinglists19@gmail.com> wrote:
>>>>> 
>>>>>> Is there a UDF in Piggybank (or somewhere) that will mimic
>>> functionality
>>>>> of
>>>>>> the COALESCE function in MySQL:
>> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
>>>>>> 
>>>>>> I know it will be very (very) easy to write this, but just don't want
>>> to
>>>>>> create one if one already exists.  I looked but couldn't find one.
>>>>>> 
>>>>>> Please let me know.  Thanks.
>> 

Re: COALESCE UDF?

Posted by John Meagher <jo...@gmail.com>.
https://github.com/mozilla-metrics/akela/blob/master/src/main/java/com/mozilla/pig/eval/Coalesce.java

On Wed, Sep 4, 2013 at 12:40 PM, Something Something
<ma...@gmail.com> wrote:
> Serega - I think you missed this line:
>
> "....I know it will be very (very) easy to write this, but just don't want
> to create one if one already exists....."
>
> There's a saying, don't code something that's already been coded!  "Code
> Reuse" for the win!
>
> Anyway, seems like the simple answer is "NO, this doesn't exist in
> Piggybank".  Thanks.
>
>
>
> On Wed, Sep 4, 2013 at 9:10 AM, Serega Sheypak <se...@gmail.com>wrote:
>
>> Use simple jython UDF. Its 3 lines of code
>> 04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com> написал:
>>
>> > For my two cents' worth I agree, it's nicer to have coalesce than the
>> > conditional operator.
>> >
>> > On Sep 4, 2013, at 8:50 AM, Something Something <
>> mailinglists19@gmail.com>
>> > wrote:
>> >
>> > > What if you've 10 fields?
>> > >
>> > >
>> > > On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <metaruslan@gmail.com
>> > >wrote:
>> > >
>> > >> Hi,
>> > >>
>> > >> I think you could mimic it with an expression like this:
>> > >> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
>> > >> field2) : field1);
>> > >>
>> > >> Hope that helps,
>> > >> Ruslan
>> > >>
>> > >>
>> > >> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
>> > >> mailinglists19@gmail.com> wrote:
>> > >>
>> > >>> Is there a UDF in Piggybank (or somewhere) that will mimic
>> > functionality
>> > >> of
>> > >>> the COALESCE function in MySQL:
>> > >>
>> >
>> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
>> > >>>
>> > >>> I know it will be very (very) easy to write this, but just don't want
>> > to
>> > >>> create one if one already exists.  I looked but couldn't find one.
>> > >>>
>> > >>> Please let me know.  Thanks.
>> > >>
>> >
>>

Re: COALESCE UDF?

Posted by Something Something <ma...@gmail.com>.
Serega - I think you missed this line:

"....I know it will be very (very) easy to write this, but just don't want
to create one if one already exists....."

There's a saying, don't code something that's already been coded!  "Code
Reuse" for the win!

Anyway, seems like the simple answer is "NO, this doesn't exist in
Piggybank".  Thanks.



On Wed, Sep 4, 2013 at 9:10 AM, Serega Sheypak <se...@gmail.com>wrote:

> Use simple jython UDF. Its 3 lines of code
> 04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com> написал:
>
> > For my two cents' worth I agree, it's nicer to have coalesce than the
> > conditional operator.
> >
> > On Sep 4, 2013, at 8:50 AM, Something Something <
> mailinglists19@gmail.com>
> > wrote:
> >
> > > What if you've 10 fields?
> > >
> > >
> > > On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <metaruslan@gmail.com
> > >wrote:
> > >
> > >> Hi,
> > >>
> > >> I think you could mimic it with an expression like this:
> > >> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
> > >> field2) : field1);
> > >>
> > >> Hope that helps,
> > >> Ruslan
> > >>
> > >>
> > >> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
> > >> mailinglists19@gmail.com> wrote:
> > >>
> > >>> Is there a UDF in Piggybank (or somewhere) that will mimic
> > functionality
> > >> of
> > >>> the COALESCE function in MySQL:
> > >>
> >
> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
> > >>>
> > >>> I know it will be very (very) easy to write this, but just don't want
> > to
> > >>> create one if one already exists.  I looked but couldn't find one.
> > >>>
> > >>> Please let me know.  Thanks.
> > >>
> >
>

Re: COALESCE UDF?

Posted by Serega Sheypak <se...@gmail.com>.
Use simple jython UDF. Its 3 lines of code
04.09.2013 18:04 пользователь "Sajid Raza" <wi...@gmail.com> написал:

> For my two cents' worth I agree, it's nicer to have coalesce than the
> conditional operator.
>
> On Sep 4, 2013, at 8:50 AM, Something Something <ma...@gmail.com>
> wrote:
>
> > What if you've 10 fields?
> >
> >
> > On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <metaruslan@gmail.com
> >wrote:
> >
> >> Hi,
> >>
> >> I think you could mimic it with an expression like this:
> >> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
> >> field2) : field1);
> >>
> >> Hope that helps,
> >> Ruslan
> >>
> >>
> >> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
> >> mailinglists19@gmail.com> wrote:
> >>
> >>> Is there a UDF in Piggybank (or somewhere) that will mimic
> functionality
> >> of
> >>> the COALESCE function in MySQL:
> >>
> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
> >>>
> >>> I know it will be very (very) easy to write this, but just don't want
> to
> >>> create one if one already exists.  I looked but couldn't find one.
> >>>
> >>> Please let me know.  Thanks.
> >>
>

Re: COALESCE UDF?

Posted by Sajid Raza <wi...@gmail.com>.
For my two cents' worth I agree, it's nicer to have coalesce than the conditional operator.

On Sep 4, 2013, at 8:50 AM, Something Something <ma...@gmail.com> wrote:

> What if you've 10 fields?
> 
> 
> On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <me...@gmail.com>wrote:
> 
>> Hi,
>> 
>> I think you could mimic it with an expression like this:
>> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
>> field2) : field1);
>> 
>> Hope that helps,
>> Ruslan
>> 
>> 
>> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
>> mailinglists19@gmail.com> wrote:
>> 
>>> Is there a UDF in Piggybank (or somewhere) that will mimic functionality
>> of
>>> the COALESCE function in MySQL:
>> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
>>> 
>>> I know it will be very (very) easy to write this, but just don't want to
>>> create one if one already exists.  I looked but couldn't find one.
>>> 
>>> Please let me know.  Thanks.
>> 

Re: COALESCE UDF?

Posted by Something Something <ma...@gmail.com>.
What if you've 10 fields?


On Wed, Sep 4, 2013 at 4:30 AM, Ruslan Al-Fakikh <me...@gmail.com>wrote:

> Hi,
>
> I think you could mimic it with an expression like this:
> b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
> field2) : field1);
>
> Hope that helps,
> Ruslan
>
>
> On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
> mailinglists19@gmail.com> wrote:
>
> > Is there a UDF in Piggybank (or somewhere) that will mimic functionality
> of
> > the COALESCE function in MySQL:
> >
> >
> >
> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
> >
> > I know it will be very (very) easy to write this, but just don't want to
> > create one if one already exists.  I looked but couldn't find one.
> >
> > Please let me know.  Thanks.
> >
>

Re: COALESCE UDF?

Posted by Ruslan Al-Fakikh <me...@gmail.com>.
Hi,

I think you could mimic it with an expression like this:
b = foreach a generate ((field1 is null) ? ((field2 is null) ? null :
field2) : field1);

Hope that helps,
Ruslan


On Wed, Sep 4, 2013 at 9:50 AM, Something Something <
mailinglists19@gmail.com> wrote:

> Is there a UDF in Piggybank (or somewhere) that will mimic functionality of
> the COALESCE function in MySQL:
>
>
> http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php
>
> I know it will be very (very) easy to write this, but just don't want to
> create one if one already exists.  I looked but couldn't find one.
>
> Please let me know.  Thanks.
>