@Description( name = "xpath_long", value = "_FUNC_(xml, xpath) - Returns a long value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3") public class UDFXPathLong extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public long evaluate(String xml, String path) { return xpath.evalNumber(xml, path).longValue(); } }
@Description( name = "xpath_number,xpath_double", value = "_FUNC_(xml, xpath) - Returns a double value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3.0") public class UDFXPathDouble extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public double evaluate(String xml, String path) { return xpath.evalNumber(xml, path).doubleValue(); } }
@Description( name = "xpath_float", value = "_FUNC_(xml, xpath) - Returns a float value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3.0") public class UDFXPathFloat extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public float evaluate(String xml, String path) { return xpath.evalNumber(xml, path).floatValue(); } }
/** * Source for UDFBuildVersion. */ @Description(name = "buildversion", value = "_FUNC_() - Returns the Hive build version string - includes base" + "version, revision, User, Source Check Sum") public class UDFBuildVersion extends UDF { private static final String VERSIONINFO = String.format("%s", HiveVersionInfo.getBuildVersion()); public Text evaluate() { return new Text(VERSIONINFO); } }
@Description( name = "xpath_short", value = "_FUNC_(xml, xpath) - Returns a short value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3") public class UDFXPathShort extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public short evaluate(String xml, String path) { return xpath.evalNumber(xml, path).shortValue(); } }
@Description(name = "IS DISTINCT FROM", value = "a _FUNC_ b - Returns same result with NOTEQUALNS (IS DISTINCT " + "FROM) operator for non-null operands, but returns FALSE if both are NULL, TRUE if one of the them is NULL") public GenericUDFOPNotEqualNS(){ this.opName = "NOTEQUALNS"; this.opDisplayName = "IS DISTINCT FROM"; }
/** * UDFExampleFormat. * */ @Description(name = "example_format", value = "_FUNC_(expr) - Example UDAF that returns formated String") public class UDFExampleFormat extends UDF { public String evaluate(String format, Object... args) { return String.format(format, args); } }
@Description( name = "xpath_int", value = "_FUNC_(xml, xpath) - Returns an integer value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3") public class UDFXPathInteger extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public int evaluate(String xml, String path) { return xpath.evalNumber(xml, path).intValue(); } }
/** * UDFVersion */ @Description(name = "version", value="_FUNC_() - Returns the Hive build version string - includes base " + "version and revision.") public class UDFVersion extends UDF { private static final String versionInfo = String.format("%s r%s", HiveVersionInfo.getVersion(), HiveVersionInfo.getRevision()); public Text evaluate() { return new Text(versionInfo); } }
@Description(name = "mask_hash", value = "returns hash of the given value", extended = "Examples:\n " + " mask_hash(value)\n " + "Arguments:\n " + " value - value to mask. Supported types: STRING, VARCHAR, CHAR" ) public class GenericUDFMaskHash extends BaseMaskUDF { public static final String UDF_NAME = "mask_hash"; public GenericUDFMaskHash() { super(new MaskHashTransformer(), UDF_NAME); } }
@Description(name = "base64", value = "_FUNC_(bin) - Convert the argument from binary to a base 64 string") public class UDFBase64 extends UDF { private final transient Text result = new Text(); public Text evaluate(BytesWritable b){ if (b == null) { return null; } byte[] bytes = new byte[b.getLength()]; System.arraycopy(b.getBytes(), 0, bytes, 0, b.getLength()); result.set(Base64.encodeBase64(bytes)); return result; } }
@Description( name = "xpath_boolean", value = "_FUNC_(xml, xpath) - Evaluates a boolean xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b></a>','a/b') FROM src LIMIT 1;\n" + " true\n" + " > SELECT _FUNC_('<a><b>1</b></a>','a/b = 2') FROM src LIMIT 1;\n" + " false") public class UDFXPathBoolean extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil () ; public boolean evaluate(String xml, String path) { return xpath.evalBoolean(xml, path).booleanValue(); } }
@Description( name = "xpath_number,xpath_double", value = "_FUNC_(xml, xpath) - Returns a double value that matches the xpath expression", extended = "Example:\n" + " > SELECT _FUNC_('<a><b>1</b><b>2</b></a>','sum(a/b)') FROM src LIMIT 1;\n" + " 3.0") public class UDFXPathDouble extends UDF { private final UDFXPathUtil xpath = new UDFXPathUtil(); public double evaluate(String xml, String path) { return xpath.evalNumber(xml, path).doubleValue(); } }
@Description( name = "longudf", value = "_FUNC_(arg) - returns arg + 1000", extended = "Example:\n" + " > SELECT longudf(eno) FROM employee;\n" ) public class LongUDF extends UDF { public LongWritable evaluate(LongWritable i) { if (i == null) { return null; } return new LongWritable(i.get() + 1000); } }
@Description(name = "testHiveUDFBOOLEAN", value = "_FUNC_(BOOLEAN) - Tests boolean data as input and output") public static class GenericUDFTestBOOLEAN extends GenericUDFTestBase { public GenericUDFTestBOOLEAN() { super("testHiveUDFBOOLEAN", PrimitiveCategory.BOOLEAN); } }
@Description(name = "testHiveUDFBYTE", value = "_FUNC_(BYTE) - Tests byte data as input and output") public static class GenericUDFTestBYTE extends GenericUDFTestBase { public GenericUDFTestBYTE() { super("testHiveUDFBYTE", PrimitiveCategory.BYTE); } }
@Description(name = "testHiveUDFSHORT", value = "_FUNC_(SHORT) - Tests short data as input and output") public static class GenericUDFTestSHORT extends GenericUDFTestBase { public GenericUDFTestSHORT() { super("testHiveUDFSHORT", PrimitiveCategory.SHORT); } }
@Description(name = "testHiveUDFCHAR", value = "_FUNC_(VARCHAR) - Tests varchar data as input and char data as output") public static class GenericUDFTestCHAR extends GenericUDFTestBase { public GenericUDFTestCHAR() { super("testHiveUDFCHAR", PrimitiveCategory.VARCHAR, PrimitiveCategory.CHAR); } }
@Description(name = "testHiveUDFBINARY", value = "_FUNC_(BINARY) - Tests binary data as input and output") public static class GenericUDFTestBINARY extends GenericUDFTestBase { public GenericUDFTestBINARY() { super("testHiveUDFBINARY", PrimitiveCategory.BINARY); } }
@UDFType(deterministic = false, runtimeConstant = true) @Description(name = "current_schema", value = "_FUNC_() - returns currently used schema(database) name") @NDV(maxNdv = 1) public class GenericUDFCurrentSchema extends GenericUDFCurrentDatabase { @Override public String getDisplayString(String[] children) { return "current_schema()"; } }