1.下载源码
wget http://archive.cloudera.com/cdh5/cdh/5/hive-1.1.0-cdh5.7.0-src.tar.gz
2.解压下载的源码
3.自己定义一个Java类继承UDF
…
package com.spark.udf.hive;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
/**
- 一个UDF: sayhello
*/
@Description(name = “sayhello”,
value = "FUNC(input_str) - returns Hello : input_str “,
extended = “Example:\n "
+ " > SELECT FUNC(‘wxk’) FROM src LIMIT 1;\n”
+ " ‘Hello : wxk’\n”)
public class sayhello extends UDF {
public Text evaluate(Text input){
System.out.println("sayhello methond start......");
return new Text("Hello"+input);
}
}