Impala 中运行 Hive UDF
场景:部分查询需要快速返回,使用Impala进行快速、复杂的查询
- 1.简单的UDF函数过滤,判断是否包含“好”字,返回boolean类型
import org.apache.hadoop.hive.ql.exec.UDF;/*** @ClassName: UdfTest* @Description: TODO * @author: Jast* @date: 2019年3月10日 上午11:30:20  */
public class UdfTest  extends UDF {public boolean evaluate(String text){if(text.contains("好")) {return true;}else {return false;}}
}
- 2.将jar包上传到HDFS中
hdfs dfs -put /home/xxx/hive-udf.jar /user/hive/lib- 3.创建函数
create function if not exists udftest(String) returns boolean location "/user/hive/lib/hive-udf.jar" SYMBOL="com.xxx.udftest";- 4.查看是否创建成功
[hostname:21000] dw_xxxx> show functions;
Query: show functions
+-------------+----------------------+-------------+---------------+
| return type | signature            | binary type | is persistent |
+-------------+----------------------+-------------+---------------+
| BOOLEAN     | udftest(STRING)      | JAVA        | false         |
+-------------+----------------------+-------------+---------------+
Fetched 1 row(s) in 0.01s- 5.查询结果
