hive自定义函数
pom文件
<dependencies> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-exec</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>3.0.0</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>
生成0-15随机数java代码
import org.apache.hadoop.hive.ql.exec.UDF; import java.util.Random; public class RandomUDF extends UDF { public int evaluate(String str) { Random random = new Random(); int i = random.nextInt(16); return i; } public static void main(String[] args) { RandomUDF randomUDF=new RandomUDF(); System.out.println(randomUDF.evaluate("fff")); } }
上传hdfs目录
hdfs dfs -put /tmp/hiveudf16.jar hdfs:///tmp/
在impala创建函数或在hue界面
create function if not exists getuuid(STRING) returns int location 'hdfs:///tmp/hiveudf16.jar' symbol='com.sunward.hive.RandomUDF';
删除自定义函数
drop function getuuid(STRING);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)