Last active
September 21, 2016 04:38
-
-
Save amaya382/1f08072ee08568e855a27670a23766ee to your computer and use it in GitHub Desktop.
skeleton for GenericUDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package somewhere; | |
import org.apache.hadoop.hive.ql.exec.Description; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentException; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; | |
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; | |
import org.apache.hadoop.hive.ql.metadata.HiveException; | |
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; | |
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | |
@Description(name = "skeleton", | |
value = "_FUNC_(something) - Returns something") | |
public class SkeletonUDF extends GenericUDF { | |
// declare OIs | |
@Override | |
public ObjectInspector initialize(ObjectInspector[] OIs) throws UDFArgumentException { | |
if (OIs.length != 0) { | |
throw new UDFArgumentLengthException("Specify arguments."); | |
} | |
if (/*check type of OIs*/) { | |
throw new UDFArgumentTypeException(0, "Only type argument is acceptable but " | |
+ OIs[0].getTypeName() + " was passed as ``"); | |
} | |
// init OIs | |
return null; | |
} | |
@Override | |
public Object evaluate(GenericUDF.DeferredObject[] dObj) throws HiveException { | |
// process and return writable value | |
return null; | |
} | |
@Override | |
public String getDisplayString(String[] children) { | |
final StringBuilder sb = new StringBuilder(); | |
sb.append("skeleton"); | |
sb.append("("); | |
if (children.length > 0) { | |
sb.append(children[0]); | |
for (int i = 1; i < children.length; i++) { | |
sb.append(", "); | |
sb.append(children[i]); | |
} | |
} | |
sb.append(")"); | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment