--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')