<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>2.7.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.5</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>
</plugins>
</build>
/**
* @Author hwj
* @Date 2020/8/5 20:15
* @Desc: 模拟hive的upper方法:将字符串的第一个字母转大写,其它不变
**/
public class MyUDF extends UDF {
public Text evaluate(final Text line){
if(line.toString()!=null&& ! line.toString().equals("")){
String str=line.toString().substring(0,1).toUpperCase()+line.toString().substring(1);
return new Text(str);
}
return new Text("");
}
}
cd /export/servers/apache-hive-2.1.1-bin/lib
mv hive_udf_upper-1.0-SNAPSHOT.jar Upper.jar
add jar /export/servers/apache-hive-2.1.1-bin/lib/Upper.jar;
create temporary function Upper as ‘pers.hwj.udf.MyUDF‘;
select Upper(‘hwj2020‘);
源码请地访问github,对应标题下download
原文:https://www.cnblogs.com/alidata/p/13442669.html