Created 05-11-2017 08:42 AM
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;
import org.apache.hadoop.io.Text;
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;
else
{
int ajax = 0; int java = 0;
String[] worduse = word.split(" ");
int len = worduse.length;
int pos = 0;
while (pos < len)
{
if(worduse[pos].toLowerCase().contains("ajax"))
ajax++;
if(worduse[pos].toLowerCase().contains("java"))
java++; pos++;
}
data[0] = Integer.toString(ajax);
data[1] = Integer.toString(java);
}
result.set(data.toString());
return result;
}
}"