Hive UDF return expected result but also added null and newline in result

126 Views Asked by At

I have written Hive UDF in Java for decoding the information, for that we used the below code.

public Text evaluate(Text str) throws Exception {
        byte[] keyBytes = (SALT + KEY).getBytes("UTF8");
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
        keyBytes = messageDigest.digest(keyBytes);
        keyBytes = java.util.Arrays.copyOf(keyBytes, 16);
        SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        String decryptedString = Base64.encodeBase64String(cipher.doFinal(str.getBytes()));
        return new Text(decryptedString);
    }

The below query is executed successfully with UDF.

Hive Query to check UDF is working

below is the Gender table where I'm executing the UDF

Whole Gender table

When I execute the query on the gender table with UDF, I'm getting the null and new line in it. Please find the below screenshot with highlighted areas. Query with UDF

I'm expecting the result in one line only. Please help and let me know where I'm wrong.

0

There are 0 best solutions below