Support Questions
Find answers, ask questions, and share your expertise

Hive UDF not working correctly

Hive UDF not working correctly

New Contributor

Hello all, I have written a UDF for hive to extract the number of entries in a table with String type column.

I basically need to find the number of occurrences of the word 'java' and 'ajax' and get the number printed as the output. when i follow all the steps and execute the udf in the console, i get no errors, but don't get the output either.

All i get is the total number of rows in the table. Below is the udf code which i used.

Please help me to know what wrong am i doing here -

"package com.hive.udf;

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


public class Test extends UDF {

Text result = new Text();

public Text evaluate(Text str)


String word = str.toString();

String[] data = new String[100];

if(word == null ) return null;



int ajax = 0; int java = 0;

String[] worduse = word.split(" ");

int len = worduse.length;

int pos = 0;

while (pos < len)





java++; pos++;


data[0] = Integer.toString(ajax);

data[1] = Integer.toString(java);



return result;



Don't have an account?