Im trying to write a Hive UDF which checks a column in a Hive table and concatenates a string with it. my Hive table- cityTab schema and data:
Schema:
id int
name char(30)
rank int
Data:
1 NewYork 10
2 Amsterdam 30
I wrote the following Hive UDF:
public class MyHiveUdf extends UDF {
private Text result = new Text();
public Text evaluate(Text text) {
if(text == null) {
return null;
} else {
String str = text.toString();
if(str.contains("NewYork")) {
result.set(text.toString().concat(" America"));
}
return result;
}
}
}
I added the jar, created a temporary function and executed it like below:
ADD jar /home/cloudera/Desktop/HiveStrCon.jar;
create temporary function strcon as 'com.hiveudf.strmnp.MyHiveUdf';
select strcon(name) from cityTab;
But I see the output data without any concatenation of the new string:
OK
NewYork
Amsterdam
Time taken: 0.191 seconds, Fetched: 3 row(s)
Can anyone tell me what is the mistake I am making here.