hive 之用户自定义函数
一、quickstart 项目
pom中:
<repositories> <repository> <id>cloudera</id> <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url> </repository> </repositories> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <hive.version>1.2.1</hive.version> <hadoop.version>2.7.3</hadoop.version> <jdk.version>0.11.0.0-cp1</jdk.version> <junit.version>4.12</junit.version> <mvnshade.version>2.4.1</mvnshade.version> <confluent.maven.repo>http://packages.confluent.io/maven/</confluent.maven.repo> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-exec</artifactId> <version>${hive.version}</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>${hadoop.version}</version> </dependency> </dependencies>
二、目录
package cn.kb08.udxf.udf;
public class InString extends UDF {
// 一定是evaluate方法,否则不识别 public boolean evaluate(String str,String subStr){ return null != str && null != subStr && str.length()>0 && subStr.length()<=str.length() && str.indexOf(subStr)>=0; } }
三、发布
1)maven-package打成jar包(如果用普通方式,需要增加个文件)
![](https://img2020.cnblogs.com/blog/2112373/202008/2112373-20200831094348375-13303740.png)
2)beeline中:
add/delete jar /root/kb08/hive/hiveudxf-1.0-SNAPSHOT.jar
create/drop temporary function within as 'cn.kb08.udxf.udf.InString'
>>> 临时函数,会话结束就没了
3)show functions看看有没有within函数
4)select within('123123','123') ---> true