当前位置: 首页 > news >正文

cdh6.3.2的hive配udf

背景

大数据平台的租户要使用udf,他们用beeline连接,
意味着要通过hs2,但如果有多个hs2,各个hs2之间不能共享,需要先把文件传到hdfs,然后手动在各hs2上create function。之后就可以永久使用了,重启hs2也可以

调研

先查的hive官网

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-CreatingCustomUDFs
在这里插入图片描述
用beeline执行add jar 和create function,但发现只在当前的hs2生效

然后查cdh官网

cdh的官网上说配UDF,需要考虑是否重启hs2,是否启用sentry,列出了3种方案。
https://docs.cloudera.com/documentation/enterprise/latest/topics/cm_mc_hive_udf.html
在这里插入图片描述
Direct JAR reference configuration
Straight-forward, but recommended for development only. Does not support Sentry.
试了下,是永久的,重启仍然生效,但只对当前的hs2有效,如果有多个hs2,需要在每个hs2上都执行create function命令
虽然我们开了sentry,但没影响,sentry仍然有效

pom

<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>sm3UDF</artifactId><version>1.0</version><packaging>jar</packaging><name>sm3UDF</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.bouncycastle</groupId><artifactId>bcprov-jdk15on</artifactId><version>1.68</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>3.1.1</version></dependency>
<!--        <dependency>-->
<!--            <groupId>junit</groupId>-->
<!--            <artifactId>junit</artifactId>-->
<!--            <version>4.13.2</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>--><dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>2.1.1-cdh6.3.2</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
</project>

java

package org.picc.encrypt;import org.apache.commons.codec.binary.Hex;
import org.apache.hadoop.io.Text;
import org.bouncycastle.crypto.digests.SM3Digest;
import org.apache.hadoop.hive.ql.exec.UDF;public class Sm3Fun extends UDF{public static String sm3(String saltBefore, String text, String saltAfter) {if (text == null) {return null;}Text result = new Text();SM3Digest digest = new SM3Digest();Text sb = new Text(saltBefore);Text value = new Text(text);Text sa = new Text(saltAfter);byte[] hashData = new byte[32];digest.reset();digest.update(sb.getBytes(), 0, sb.getLength());digest.update(value.getBytes(), 0, value.getLength());digest.update(sa.getBytes(), 0, sa.getLength());digest.doFinal(hashData, 0);String sm3Hex = Hex.encodeHexString(hashData);result.set(sm3Hex);return result.toString();}public String evaluate(String text) {if (text == null) {return null;}Text result = new Text();SM3Digest digest = new SM3Digest();Text value = new Text(text);byte[] hashData = new byte[32];digest.reset();digest.update(value.getBytes(), 0, value.getLength());digest.doFinal(hashData, 0);String sm3Hex = Hex.encodeHexString(hashData);result.set(sm3Hex);return result.toString();}
}
http://www.lryc.cn/news/287926.html

相关文章:

  • 在DevEco开发工具中,使用Previewer预览界面中的UI组件
  • 【蓝桥杯冲冲冲】旅行计划
  • Ultraleap 3Di配置以及在 Unity 中使用 Ultraleap 3Di手部跟踪
  • HarmonyOS鸿蒙学习基础篇 - Text文本组件
  • pytorch学习笔记(十一)
  • 【并发编程】 synchronized的普通方法,静态方法,锁对象,锁升级过程,可重入锁,非公平锁
  • jQuery 删除元素 —— W3school 详解 简单易懂(十四)
  • 在 Linux 上搭建 Java 环境
  • 深度学习-Pytorch如何保存和加载模型
  • 2.数据结构 顺序表(自留笔记)
  • 将python打包成exe文件
  • 大数据处理,Pandas与SQL高效读写大型数据集
  • 【2024年5月备考新增】《软考高项论文专题 (2)论文背景(合集)》
  • Mysql复习1--理论基础+操作实践--更新中
  • 微信小程序打卡定位实现方案
  • 小迪安全23WEB 攻防-Python 考点CTF 与 CMS-SSTI 模版注入PYC 反编译
  • 计算机毕业设计 基于SpringBoot的律师事务所案件管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 如何使用宝塔面板配置Nginx反向代理WebSocket(wss)
  • vulhub之redis篇
  • Lua简介和应用场景介绍
  • 【手写数据库toadb】10 开发数据库内核开发阶段-数据库模型
  • 02-Redis持久化、主从与哨兵架构详解
  • 无刷电机篇(一)直流无刷电机(BLDC)介绍
  • 【GitHub项目推荐--不错的Flutter项目】【转载】
  • Unity UnityWebRequest 向php后端上传图片文件
  • Vscode 顶部Menu(菜单)栏消失如何恢复
  • Jenkins相关
  • 禅道的安装以及使用
  • 马尔可夫预测(Python)
  • 双向队列的创建队首与队尾的操作deque()