[ 
https://issues.apache.org/jira/browse/HIVE-5306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13771299#comment-13771299
 ] 

Jason Dere commented on HIVE-5306:
----------------------------------

Couple comments:

1. You can probably get away with making all of the fields transient.
2. Since you've only defined abs() to work with int/long/double/decimal, I 
believe initialize() will fail if abs() is called with other types which one 
might expect to work, such as tinyint/smallint/float/string.  For non-generic 
UDFs, what would happen would be that FunctionRegistry.getMethodInternal() 
would determine that tinyint/smallint/float/string could be converted to one of 
int/long/double/decimal and make the conversion at the time the UDF is called. 
Unfortunately for GenericUDFs, I think you have to do that logic yourself.

Maybe you can do something like so:
(define Converter inputConvertor)
    switch (inputType) {
    case BYTE:
    case SHORT:
    case INT:
      // Use converter to convert input type to your supported type
      inputConverter = ObjectInspectorConvertors.getConvertor(arguments[0], 
PrimitiveObjectInspectorFactory.writableIntObjectInspector);
      outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
      break;
    case LONG:
      inputConvertor = ObjectInspectorConvertors.getConvertor(arguments[0], 
PrimitiveObjectInspectorFactory.writableLongObjectInspector);
      outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
      break;
    ...


                
> Use new GenericUDF instead of basic UDF for UDFAbs class
> --------------------------------------------------------
>
>                 Key: HIVE-5306
>                 URL: https://issues.apache.org/jira/browse/HIVE-5306
>             Project: Hive
>          Issue Type: Improvement
>          Components: UDF
>            Reporter: Mohammad Kamrul Islam
>            Assignee: Mohammad Kamrul Islam
>         Attachments: HIVE-5306.1.patch, HIVE-5306.2.patch, HIVE-5306.3.patch
>
>
> GenericUDF class is the latest  and recommended base class for any UDFs.
> This JIRA is to change the current UDFAbs class extended from GenericUDF.
> The general benefit of GenericUDF is described in comments as 
> "* The GenericUDF are superior to normal UDFs in the following ways: 1. It can
>  * accept arguments of complex types, and return complex types. 2. It can 
> accept
>  * variable length of arguments. 3. It can accept an infinite number of 
> function
>  * signature - for example, it's easy to write a GenericUDF that accepts
>  * array<int>, array<array<int>> and so on (arbitrary levels of nesting). 4. 
> It
>  * can do short-circuit evaluations using DeferedObject."  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to