Hive custom UDF and aggregate function UDAF

1. Hive allows users to write their own defined function UDFs to use in queries.

There are 3 kinds of UDFs in Hive:

       UDF: operate on a single data row to generate a single data row;

       UDAF: Operates on multiple data rows to generate one data row.

       UDTF: Operates on a data row, generating multiple data rows and a table as output.

 

Second, write your own defined function UDF

      Step 1: Inherit UDF or UDAF or UDTF and implement specific methods.

      Step 2: Package the written class as a jar. Such as hivefirst.jar.

      Step 3: Enter the Hive shell environment and use add jar /home/hadoop/hivefirst.jar. to register the jar file

      Step 4: Create an alias for this class, create temporary function mylength as 'com.whut.StringLength'; here note that UDF is only temporarily defined for this Hive session.

      Step 5: Use mylength() in select;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326670935&siteId=291194637