context:decompress the 使用hive udf evaluate()方法的列数据
例外情况:
失败,出现异常java.io.ioexception:org.apache.hadoop.hive.ql.metadata.hiveexception:无法执行方法public static org.apache.hadoop.io.text test.udfdecompressor.evaluate(java.lang.string)在对象测试上抛出org.apache.hadoop.hive.ql.metadata.hiveexception。udfdecompressor@1008df1e 类test.udfdecompressor的参数{x��}千瓦⸲�_一�����ö¤ï¿½\��a-b型�我�@`�����"�第三次�我����$_�e�� } 大小1
源代码:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.zip.DataFormatException;
import java.util.zip.InflaterInputStream;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaStringObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
public class Decompress extends UDF{
public static String evaluate(String data1) throws IOException, DataFormatException{
ByteArrayInputStream bao=new ByteArrayInputStream(data1.getBytes());
InflaterInputStream iis= new InflaterInputStream(bao);
String out="";
byte[] bt=new byte[1024];
int len=-1;
while ((len =iis.read(bt))!=-1){
out += new String(Arrays.copyOf(bt, len));
}
JavaStringObjectInspector stringInspector;
stringInspector = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
String ip = stringInspector.getPrimitiveJavaObject(out);
//return new String(ip.getBytes(Charset.forName("UTF-8")));
//return new String(ip.getBytes(Charset.forName("UTF-8")));
return ip;
}
}
我尝试了多种方法来使用gzib、zlibjavaapi解压,但是遇到了相同的错误。有谁能帮助我解决这个问题,并建议使用hiveudf解压列数据的正确方法吗
提前谢谢。
1条答案
按热度按时间frebpwbc1#