--udf开发
--1.java开发环境(jdk,maven)
--2.配置maven依赖,比如hive或者flink库等
https://mvnrepository.com/search?q=Maven
****<projectxmlns="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.本机开发代码,并测试:
例子:https://blog.csdn.net/qq_15783243/article/details/83654713
packagehive; importorg.apache.hadoop.hive.ql.exec.UDF; publicclassUDF_LowerextendsUDF { publicStringevaluate(finalStrings){ if(s==null){ returnnull; } returns.toLowerCase(); } }
--4.maven打包上传
通过Maven打成jar包:clean--》package
maven各种打包方案总结:
https://www.cnblogs.com/swordfall/p/11359370.html
https://blog.csdn.net/dyq51/article/details/81356894
--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')