You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Aurora Skarra-Gallagher <au...@yahoo-inc.com> on 2011/02/15 17:53:52 UTC

In UDAF, possible for terminatePartial to be called without init?

Hi,

I wrote a simple UDAF for Hive 0.6 and I had to include null checks in terminatePartial even though the object should never be null if init is always called before terminatePartial.

For instance, my init function:
        public void init() {
            result = new StringBuffer();
        }

My terminatePartial function:
        public String terminatePartial() {
            if (result == null) {
                return new String();
            }
            
            // Remove trailing comma, if string isn't blank
            if (result.length() > 0 && result.charAt(result.length() - 1) == ',') {
                result.deleteCharAt(result.length() - 1);
            }
            
            return result.toString();
        }

If I don't have that initial null check, when the results are empty that I'm applying my UDAF to, I get a NullPointerException. It makes me think that terminatePartial can be called with no init call. Is that possible?

Thanks,
Aurora

Re: In UDAF, possible for terminatePartial to be called without init?

Posted by Aurora Skarra-Gallagher <au...@yahoo-inc.com>.
Anyone know the answer to this?

Thanks,
Aurora

On Feb 15, 2011, at 8:53 AM, Aurora Skarra-Gallagher wrote:

> Hi,
> 
> I wrote a simple UDAF for Hive 0.6 and I had to include null checks in terminatePartial even though the object should never be null if init is always called before terminatePartial.
> 
> For instance, my init function:
>        public void init() {
>            result = new StringBuffer();
>        }
> 
> My terminatePartial function:
>        public String terminatePartial() {
>            if (result == null) {
>                return new String();
>            }
> 
>            // Remove trailing comma, if string isn't blank
>            if (result.length() > 0 && result.charAt(result.length() - 1) == ',') {
>                result.deleteCharAt(result.length() - 1);
>            }
> 
>            return result.toString();
>        }
> 
> If I don't have that initial null check, when the results are empty that I'm applying my UDAF to, I get a NullPointerException. It makes me think that terminatePartial can be called with no init call. Is that possible?
> 
> Thanks,
> Aurora


Re: In UDAF, possible for terminatePartial to be called without init?

Posted by Amareshwari Sri Ramadasu <am...@yahoo-inc.com>.
init() is called for all the aggregation evaluators, then terminatePartial() is called.

In your code, init() function is not overriding  GenericUDAFEvaluator.init(Mode m, ObjectInspector[] parameters). Hive calls GenericUDAFEvaluator.init.

Was the signature of the method wrong in your code?

Thanks
Amareshwari


On 2/15/11 10:23 PM, "Aurora Skarra-Gallagher" <au...@yahoo-inc.com> wrote:

Hi,

I wrote a simple UDAF for Hive 0.6 and I had to include null checks in terminatePartial even though the object should never be null if init is always called before terminatePartial.

For instance, my init function:
        public void init() {
            result = new StringBuffer();
        }

My terminatePartial function:
        public String terminatePartial() {
            if (result == null) {
                return new String();
            }

            // Remove trailing comma, if string isn't blank
            if (result.length() > 0 && result.charAt(result.length() - 1) == ',') {
                result.deleteCharAt(result.length() - 1);
            }

            return result.toString();
        }

If I don't have that initial null check, when the results are empty that I'm applying my UDAF to, I get a NullPointerException. It makes me think that terminatePartial can be called with no init call. Is that possible?

Thanks,
Aurora