I created the following Java class and added it to Hive after making a jar out of it
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class MakeCap extends UDF{
private Text t;
public Text evaluate(Text input){
if(null==input){
t.set("Invalid input");
}else{
t.set(input.toString().toUpperCase());
}
return t;
}
}
Next, I created a temporary function
CREATE TEMPORARY FUNCTION CAP AS 'com.iris.MakeCap';
But when I run
SELECT CAP('hello');
I get the following error
Error: Error while compiling statement: FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments ''hello'': org.apache.hadoop.hive.ql.metadata.HiveException:
Unable to execute method public org.apache.hadoop.io.Text com.iris.MakeCap.evaluate(org.apache.hadoop.io.Text)
with arguments {hello}:null (state=42000,code=10014)
I tried to use String instead of Text as the argument type for evaluate() but got the same result. Then I also tried this
SELECT CAP(e.name) FROM default.emp e;
and got the same error. Could someone help me with this?
Try to replace Hadoop's
Texttype with simple Java'sStringtype for both input and return. ForUDFclass it works fine. If you want to stick withTextI think you need to initialize your private variablet, e.g.Here is an example code of Hive's UDF.