You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Doug Daniels <dd...@mortardata.com> on 2011/09/30 00:56:05 UTC

python UDF that returns None

I'm writing a python UDF that returns a tuple with three fields.  I'm wondering if it's ok to return None if for some reason I can't build the tuple, but don't want to throw an Exception and stop processing.

For example, on a much-simplified version of the UDF:

@outputSchema('t:tuple(a:int, b:int, c:int)')
def get_tpl(input):
    if input < 5:
        return (1, 2, 3)
    else:
        return None;

Should I be returning None or (None,  None, None).  Also, will there be any type issues if I return None back instead of a int?

Thanks,
Doug

Re: python UDF that returns None

Posted by Alan Gates <ga...@hortonworks.com>.
Returning None should result in that tuple being null, which is exactly what you want when something is wrong but you don't want to break the entire process.

Alan.

On Sep 29, 2011, at 3:56 PM, Doug Daniels wrote:

> I'm writing a python UDF that returns a tuple with three fields.  I'm wondering if it's ok to return None if for some reason I can't build the tuple, but don't want to throw an Exception and stop processing.
> 
> For example, on a much-simplified version of the UDF:
> 
> @outputSchema('t:tuple(a:int, b:int, c:int)')
> def get_tpl(input):
>    if input < 5:
>        return (1, 2, 3)
>    else:
>        return None;
> 
> Should I be returning None or (None,  None, None).  Also, will there be any type issues if I return None back instead of a int?
> 
> Thanks,
> Doug