---
title: 安装Spark/Hive UDF插件
description: "当需要把UDF函数下推到OmniData算子下推服务时，需要安装UDF依赖包，以huawei-udf为例。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/230RC5/bds/kunpengbds_omniruntime_20_0058.html
sourcePath: /source/zh/kunpengboostkithistory/230RC5/bds/kunpengbds_omniruntime_20_0058.html
indexId: a182fc99dad22129b4c0235d37a360eea946466bf7f6f14fe31b7b1f7b09f37880
---
# 安装Spark/Hive UDF插件

当需要把UDF函数下推到OmniData算子下推服务时，需要安装UDF依赖包，以huawei-udf为例。

1. HDFS上传huawei_udf.jar。

```
hdfs dfs -mkdir -p /user/BICoreData/hive/fiudflib2/
hdfs dfs -put huawei_udf.jar /user/BICoreData/hive/fiudflib2/
```


2. 运行UDF前需要将其注册到metastore，注册的方式有很多，本节以isEmpty为例。

```
set spark.sql.ndp.udf.whitelist=isEmpty;
CREATE TEMPORARY FUNCTION isEmpty AS 'com.huawei.platform.bi.udf.common.IsEmptyUDF' USING JAR 'hdfs:/user/BICoreData/hive/fiudflib2/huawei_udf.jar';
```


3. 配置Hive UDF插件。
  在OmniData算子下推 Hive UDF配置文件hive.properties中添加注册IsEmpty com.huawei.platform.bi.udf.common.IsEmptyUDF函数。详见添加OmniData算子下推 Hive UDF插件

4. 运行Spark Hive UDF算子下推。

```
/usr/local/spark/bin/spark-sql  --driver-class-path '/opt/boostkit/*' --jars '/opt/boostkit/*' --conf 'spark.executor.extraClassPath=./*' --name IsEmptyUDF.sql --driver-memory 50G --driver-java-options -Dlog4j.configuration=file:../conf/log4j.properties --executor-memory 32G --num-executors 30 --executor-cores 18 --properties-file  tpch_query.conf  --database tpch_flat_orc_date_5 -f IsEmptyUDF.sql;
```


  执行结果如下。

  IsEmptyUDF.sql文件的内容如下。 set spark.sql.ndp.udf.whitelist=isEmpty; CREATE TEMPORARY FUNCTION isEmpty AS 'com.huawei.platform.bi.udf.common.IsEmptyUDF' USING JAR 'hdfs:/user/BICoreData/hive/fiudflib2/huawei_udf.jar'; select sum(l_extendedprice) as sum_base_price from lineitem where !isEmpty(l_shipmode);
