Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

HIve UDF for converting the compressed xml column to uncompresse the xml

Highlighted

HIve UDF for converting the compressed xml column to uncompresse the xml

New Contributor

This is my Code for UiveUDF : package Test;

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.util.Arrays;

import java.util.zip.InflaterInputStream;

import org.apache.commons.io.output.ByteArrayOutputStream;

import org.apache.hadoop.hive.ql.exec.UDF;

public class Decompress extends UDF {

public static String evaluate(String data1) throws IOException{

/*ByteArrayOutputStream bos= new ByteArrayOutputStream();

DeflaterOutputStream df=new DeflaterOutputStream(bos);

df.write(data1.getBytes());

df.flush();

df.close();

System.out.println(bos);*/

System.out.println("Helooo");

ByteArrayOutputStream bos=new ByteArrayOutputStream();

byte[] decompress=data1.getBytes();

bos.write(decompress, 0, data1.length());

bos.close();

System.out.println("Helooo Hyderabad");

System.out.println(bos);

ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());

InflaterInputStream iis=new InflaterInputStream(bis);

String out=""; byte[] bt=new byte[1024]; int len=-1;

while ((len =iis.read(bt))!=-1){

out += new String(Arrays.copyOf(bt, len));

}

return out;

}

}

Excecutions Steps:

hive> add jar /home/naidu/decompress.jar;

hive> create temporary function test as 'Test.Decompress';

hive> select test(line) from deflate table;

Note: XML Column is Zlib compressed ..

when i am trying to execute this hive udf getting the below exception..please help on this .....

hive> select xyz(line) from deflate;

OK

Helooo

Helooo Hyderabad

x��}kw⸲�_a�����֤�\��a-B�i�@`�����"�nc3�I����$_�E�� �I��\:��t�R=U��b<��|6�������Y_�ï¿ï¿½ï¿½ï¿½S;�;L?�A���Ù�fn1V��Rá¥ï¿½ï¿½ï¿½ï¿½-^9h��X9X��� Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public static java.lang.String Test.Decompress.evaluate(java.lang.String) throws java.io.IOException on object Test.Decompress@6d17914a of class Test.Decompress with arguments {x��}kw⸲�_a�����֤�\��a-B�i�@`�����"�nc3�I����$_�E�� �I��\:��t�R=U��b<��|6�������Y_�ï¿ï¿½ï¿½ï¿½S;�;L?�A���Ù�fn1V��Rá¥ï¿½ï¿½ï¿½ï¿½-^9h��X9X���r~���������������a3���v���>\Of�Õ��g=Mmm~��������_���!�u}�kÕ´=��ڶ���m��A���a�ز�i@�[[>�԰dЦ^~h�.&�v� ��n�C6DE�}hh ß¡mSÕ¯&��=�>�.ƪj�:java.lang.String} of size 1

Time taken: 1.735 seconds hive>

Don't have an account?
Coming from Hortonworks? Activate your account here