我的问题是在配置单元中注册python udf。
我创建了一个用于配置单元查询的加密和解密python代码。这些都按预期工作。但是,我不想每次使用它时都添加文件,而是希望在udf中创建一个永久注册表。
我看到可以使用“创建临时函数”将JavaJAR文件添加到udf列表中。对于python,我看不到这种情况。
对任何快速的帮助表示感谢。
下面是为我工作的脚本。
vi decry.py
import base64
import sys
try:
for line in sys.stdin:
line=line.strip()
(a,b)=line.split('\t')
print('\t'.join([a,b,base64.b64decode(bytes(a.replace('\n',''),encoding='utf-8')).decode()]))
except:
print(sys.exc_info())
vi encry.py
import base64
import sys
try:
for line in sys.stdin:
line=line.strip()
(a,b)=line.split('\t')
print('\t'.join([a,b,base64.b64encode(bytes(a.replace('\n',''),encoding='utf-8')).decode()]))
except:
print(sys.exc_info())
数据库测试
create database test;
use test;
create table abc (id integer,name string);
insert into abc values(1,'vijay');
insert into abc values(2,'vaasista');
add FILE /hadoop/encry.py;
add FILE /hadoop/decry.py;
select transform(id) using 'python3 encry.py' as id from abc;
select transform(id,name) using 'python3 encry.py' as id,name,ct from
abc;
1条答案
按热度按时间col17t5w1#
首先
base64
它不是加密,而是用不同的字符集(基数64-base)编码,每个人都可以反转它,因为没有使用密钥。第二:不幸的是,使用python udf的唯一方法是在配置单元中进行转换,create[temporary]函数不支持python。
考虑使用本地函数来获得更好的性能和灵活性,像这样:
演示:
结果:
解码:
结果:
如果您需要加密,hive中还提供了aes_加密和aes_解密函数。