The hive Custom function consists of three UDFs, UDAF, UDTF
UDF (User-defined-function) one in and out
UDAF (user-defined Aggregation funcation) aggregation function, the more in one out. Count/max/min
UDTF (user-defined table-generating Functions) One more step out, such as lateral view explore ()
How to use: Add a custom function's jar file in a hive session, and then create a function to use it
Udf
1, the UDF function can be directly applied to the SELECT statement, the query structure to do the format processing, and then output the content.
2, write the UDF function when you need to pay attention to a few points:
A) custom UDFs need to inherit Org.apache.hadoop.hive.ql.UDF.
b) The Evaluate function needs to be implemented, and the Evaluate function supports overloading.
Example: Write a demo that returns the length of a string:
Import Org.apache.hadoop.hive.ql.exec.UDF; Public class extends udf{ publicint Evaluate (String str) { try{ return str.length (); } Catch (Exception e) { return -1;}} }
3. Steps
A) package the program on the target machine;
b) Enter the hive client and add the jar package:
hive> Add Jar/root/hive_udf.jar
c) Create a temporary function:
function Getlen as ' com.raphael.len.GetLength ';
d) Query the HQL statement:
Hive>Select from apachelog;ok102 0.072 9 Row (s)
e) Destroying temporary functions:
Hive>DROPtemporaryFUNCTION Getlen;
Udaf
Udtf
Hive 10, Hive UDF, Udaf, UDTF