[英]Hive UDF to convert binary(utf8) into Base64 string
我在鑲木地板文件中存儲了一個二進制節儉字段。 Parquet將其寫為二進制(UTF8),我想使用Hive UDF將其轉換為Base64 String。 它應該是非常基本的,但是不知道為什么我的代碼不起作用,這是我嘗試過的,
public class Base64Encode extends UDF {
public Text evaluate(Text bin) {
if (bin != null) {
String encoded = new String(Base64.getEncoder().encode(bin.getBytes()));
if (encoded != null) {
return new Text(encoded);
}
}
return null;
}
}
您無需為此任務創建自己的UDF。 已經定義了幾個。 在您的問題中,您說Parquet將數據存儲為二進制,但是示例代碼的參數類型為Text。
如果您的參數已經是二進制文件,則只需使用:
base64(bin_field)
否則,如果它是文本格式,並且您想將其轉換為Binary UTF-8,然后轉換為base 64,請組合:
base64(encode(text_field, 'UTF-8'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.