Hive UDF开发流程到调用

--udf开发

--1.java开发环境(jdk,maven)

--2.配置maven依赖,比如hive或者flink库等

https://mvnrepository.com/search?q=Maven

**<?xml version="1.0" encoding="UTF-8"?>
**<project xmlns="http://maven.apache.org/POM/4.0.0"
**         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
**         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
**    <modelVersion>4.0.0</modelVersion>
**
**    <groupId>org.example</groupId>
**    <artifactId>hive</artifactId>
**    <version>1.0-SNAPSHOT</version>
**
**    <dependencies> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
**        <dependency>
**            <groupId>org.apache.hive</groupId>
**            <artifactId>hive-exec</artifactId>
**            <version>3.1.1</version>
**        </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
**        <dependency>
**            <groupId>org.apache.hadoop</groupId>
**            <artifactId>hadoop-common</artifactId>
**            <version>3.1.1</version>
**        </dependency>
**    </dependencies>
**    <build>
**        <plugins>
**            <plugin>
**                <groupId>org.apache.maven.plugins</groupId>
**                <artifactId>maven-compiler-plugin</artifactId>
**                <version>3.0</version>
**                <configuration>
**                    <source>1.8</source>
**                    <target>1.8</target>
**                    <encoding>UTF-8</encoding>
**                </configuration>
**            </plugin>
**            <plugin>
**                <artifactId>maven-assembly-plugin</artifactId>
**                <configuration>
**                    <appendAssemblyId>false</appendAssemblyId>
**                    <descriptorRefs>
**                        <descriptorRef>jar-with-dependencies</descriptorRef>
**                    </descriptorRefs>
**                    <archive>
**                        <manifest>
**                            <!-- 此处指定main方法入口的class -->
**                            <mainClass>UDF_Lower</mainClass>
**                        </manifest>
**                    </archive>
**                </configuration>
**                <executions>
**                    <execution>
**                        <id>make-assembly</id>
**                        <phase>package</phase>
**                        <goals>
**                            <goal>assembly</goal>
**                        </goals>
**                    </execution>
**                </executions>
**
**            </plugin>
**
**        </plugins>
**    </build>
**
**</project>

--3.本机开发代码,并测试:

例子:​​​​​​hive UDF 开发示例_hive udf开发样例-CSDN博客

package hive;

import org.apache.hadoop.hive.ql.exec.UDF;

public class UDF_Lower extends UDF {
    public String evaluate(final String s){
        if(s==null){
            return null;
        }
        return s.toLowerCase();
    }

}

--4.maven打包上传

通过Maven打成jar包:clean--》package

maven各种打包方案总结:

https://www.cnblogs.com/swordfall/p/11359370.html

Maven 打包-添加第三方包、依赖包 mvn clean package_mvn clean package -dskiptests-CSDN博客

--5.注册函数,调用:

add jar hdfs://test-cluster//tmp/udf/01394546/38040/1000/hive-1.0-SNAPSHOT.jar;
create temporary function udf_lower as 'hive.UDF_Lower';
select udf_lower('FGGRFRD')

  • 10
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天蓝海乡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值