java - Cannot throw exception in hive udf -
java - Cannot throw exception in hive udf -
i trying larn writing udfs. code works fine when not throw exception. moment throw exception not work. if comment out else part , homecoming null, works.
public final class findpattern extends udf { private static final string strpattern= "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; public static string evaluate(string targetstring) throws udfargumentexception { // pattern matching on input pattern pattern p = pattern.compile(strpattern); matcher m = p.matcher(targetstring); string res=null; // if find match, grouping if (m.find()) { // first grouping matches res= m.group(1).concat("."+m.group(2).concat("."+m.group(3))); return("*********"+res); } else throw new udfargumentexception("ip address not valid"); } }
what wrong code? ideally throw exception saying ip address not valid.
edited ---
if throw exception -
diagnostic messages task: java.lang.runtimeexception: org.apache.hadoop.hive.ql.metadata.hiveexception: hive runtime error while processing row {"id":null,"ip":"","code":""} @ org.apache.hadoop.hive.ql.exec.execmapper.map(execmapper.java:162) @ org.apache.hadoop.mapred.maprunner.run(maprunner.java:50) @ org.apache.hadoop.mapred.maptask.runoldmapper(maptask.java:429) @ org.apache.hadoop.mapred.maptask.run(maptask.java:365) @ org.apache.hadoop.mapred.child$4.run(child.java:255) @ java.security.accesscontroller.doprivileged(native method) @ javax.security.auth.subject.doas(subject.java:396) @ org.apache.hadoop.security.usergroupinformation.doas(usergroupinformation.java:1232) @ org.apache.hadoop.mapred.child.main(child.java:249) caused by: org.apache.hadoop.hive.ql.metadata.hiveexception: hive runtime error while processing row {"id":null,"ip":"","code":""} @ org.apache.hadoop.hive.ql.exec.mapoperator.process(mapoperator.java:671) @ org.apache.hadoop.hive.ql.exec.execmapper.map(execmapper.java:144) ... 8 more caused by: org.apache.hadoop.hive.ql.metadata.hiveexception: unable execute method public static java.lang.string com.hive.udf.findpattern.evaluate(java.lang.string) throws org.apache.hadoop.hive.ql.exec.udfargumentexception on object com.hive.udf.findpattern@178ed77a of class com.hive.udf.findpattern arguments {:java.lang.string} of size 1 @ org.apache.hadoop.hive.ql.exec.functionregistry.invoke(functionregistry.java:894) @ org.apache.hadoop.hive.ql.udf.generic.genericudfbridge.evaluate(genericudfbridge.java:181) @ org.apache.hadoop.hive.ql.exec.exprnodegenericfuncevaluator.evaluate(exprnodegenericfuncevaluator.java:167) @ org.apache.hadoop.hive.ql.exec.selectoperator.processop(selectoperator.java:76) @ org.apache.hadoop.hive.ql.exec.operator.process(operator.java:502) @ org.apache.hadoop.hive.ql.exec.operator.forward(operator.java:832) @ org.apache.hadoop.hive.ql.exec.tablescanoperator.processop(tablescanoperator.java:90) @ org.apache.hadoop.hive.ql.exec.operator.process(operator.java:502) @ org.apache.hadoop.hive.ql.exec.operator.forward(operator.java:832) @ org.apache.hadoop.hive.ql.exec.mapoperator.process(mapoperator.java:652) ... 9 more caused by: java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ org.apache.hadoop.hive.ql.exec.functionregistry.invoke(functionregistry.java:870) ... 18 more caused by: org.apache.hadoop.hive.ql.exec.udfargumentexception: ip address not valid @ com.hive.udf.findpattern.evaluate(findpattern.java:27) ... 23 more
and if add together error msg homecoming string, hive udf works fine.
java hive
Comments
Post a Comment