Hallo Ich habe eine Hive-Tabelle, die Daten von sqoop hat, so gibt es ein String-Feld fc, die Nullwerte hat. Alle anderen Werte haben die Form von Zahlen. Ich habe eine UDF geschrieben, so dass ich den Wert 1000 hat erhalten können, ist es in dieser Spalte null ist und wenn es nicht null ist, sollte ich das gleiche value.My UDF-Code sieht aus wie untenFehler beim Ausführen von benutzerdefinierten udf
package com.cascrmg.customudf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
public class sample extends UDF {
int returnVal;
// Accept a string input
public int evaluate(Text input) {
// If the value is null, return a 1000
if (input == null) {
returnVal = 1000;
} else {
returnVal = Integer.parseInt(input.toString());
}
// Lowercase the input string and return it
return returnVal;
}
}
Aber als ich fügen Sie es hinzu und versuchen Sie es auszuführen, ich bekomme unten Fehler.
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public int com.cascrmg.customudf.sample.evaluate(org.apache.hadoop.io.Text) on object [email protected] of class com.cascrmg.customudf.sample with arguments {null:org.apache.hadoop.io.Text} of size 1
at org.apache.hadoop.hive.ql.exec.FunctionRegistry.invoke(FunctionRegistry.java:993)
at org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge.evaluate(GenericUDFBridge.java:182)
at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator._evaluate(ExprNodeGenericFuncEvaluator.java:186)
at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator.evaluate(ExprNodeEvaluator.java:77)
at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator.evaluate(ExprNodeEvaluator.java:65)
at org.apache.hadoop.hive.ql.exec.SelectOperator.processOp(SelectOperator.java:77)
at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815)
at org.apache.hadoop.hive.ql.exec.TableScanOperator.processOp(TableScanOperator.java:97)
at org.apache.hadoop.hive.ql.exec.MapOperator$MapOpCtx.forward(MapOperator.java:157)
at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:497)
... 9 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.hive.ql.exec.FunctionRegistry.invoke(FunctionRegistry.java:969)
... 18 more
Caused by: java.lang.NumberFormatException: For input string: "null"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at com.cascrmg.customudf.sample.evaluate(sample.java:16)
Jede Hilfe würde wirklich geschätzt werden.