Hive User Defined Function

From GM-RKB
(Redirected from Hive UDF)
Jump to navigation Jump to search

A Hive User Defined Function is a user defined function that can operate in Apache Hive.



References

2012

SHOW FUNCTIONS;
DESCRIBE FUNCTION <function_name>;
DESCRIBE FUNCTION EXTENDED <function_name>;

2012

2009

  • http://dev.bizo.com/2009/06/custom-udfs-and-hive.html
    • We just started playing around with Hive. Basically, it lets you write your hadoop map/reduce jobs using a SQL-like language. This is pretty powerful. Hive also seems to be pretty extendable -- custom data/serialization formats, custom functions, etc.

      It turns out that writing your own UDF (user defined function) for use in hive is actually pretty simple.

      All you need to do is extend UDF, and write one or more evaluate methods with a hadoop Writable return type. Here's an example of a complete implementation for a lower case function:

package com.bizo.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public final class Lower extends UDF {
  public Text evaluate(final Text s) {
    if (s == null) { return null; }
    return new Text(s.toString().toLowerCase());
  }
}