...
The following built-in mathematical functions are supported in Hive.
Return Type | Name (Signature) | Description | OSS |
---|---|---|---|
double | round(DOUBLE a) | Returns the rounded | |
double | round(DOUBLE a, INT d) | Returns | |
double | bround(DOUBLE a) | Returns the rounded BIGINT value of a using HALF_EVEN rounding mode. Also known as Gaussian rounding or bankers' rounding. Example: bround(2.5) = 2, bround(3.5) = 4. | GenericUDFBRound |
double | bround(DOUBLE a, INT d) | Returns a rounded to d decimal places using HALF_EVEN rounding mode. Example: bround(8.25, 1) = 8.2, bround(8.35, 1) = 8.4. | |
bigint | floor(DOUBLE a) | Returns the maximum | |
bigint | ceil(DOUBLE a), ceiling(DOUBLE a) | Returns the minimum BIGINT value that is equal to or greater than | |
double | rand(), rand(INT seed) | Returns a random number (that changes from row to row) that is distributed uniformly from 0 to 1. Specifying the seed will make sure the generated random number sequence is deterministic. | |
double | exp(DOUBLE a), exp(DECIMAL a) | Returns | |
double | ln(DOUBLE a), ln(DECIMAL a) | Returns the natural logarithm of the argument | |
double | log10(DOUBLE a), log10(DECIMAL a) | Returns the base-10 logarithm of the argument | |
double | log2(DOUBLE a), log2(DECIMAL a) | Returns the base-2 logarithm of the argument | |
double | log(DOUBLE base, DOUBLE a) log(DECIMAL base, DECIMAL a) | Returns the base- | |
double | pow(DOUBLE a, DOUBLE p), power(DOUBLE a, DOUBLE p) | Returns | |
double | sqrt(DOUBLE a), sqrt(DECIMAL a) | Returns the square root of | |
string | bin(BIGINT a) | Returns the number in binary format. | |
string | hex(BIGINT a) hex(STRING a) hex(BINARY a) | If the argument is an | |
binary | unhex(STRING a) | Inverse of hex. Interprets each pair of characters as a hexadecimal number and converts to the byte representation of the number. | |
string | conv(BIGINT num, INT from_base, INT to_base), conv(STRING num, INT from_base, INT to_base) | Converts a number from a given base to another. | |
double | abs(DOUBLE a) | Returns the absolute value. | |
int or double | pmod(INT a, INT b), pmod(DOUBLE a, DOUBLE b) | Returns the positive value of | |
double | sin(DOUBLE a), sin(DECIMAL a) | Returns the sine of | |
double | asin(DOUBLE a), asin(DECIMAL a) | Returns the arc sin of | |
double | cos(DOUBLE a), cos(DECIMAL a) | Returns the cosine of | |
double | acos(DOUBLE a), acos(DECIMAL a) | Returns the arccosine of | |
double | tan(DOUBLE a), tan(DECIMAL a) | Returns the tangent of | |
double | atan(DOUBLE a), atan(DECIMAL a) | Returns the arctangent of | |
double | degrees(DOUBLE a), degrees(DECIMAL a) | Converts value of | |
double | radians(DOUBLE a), radians(DOUBLE a) | Converts value of | |
int or double | positive(INT a), positive(DOUBLE a) | Returns |
int or double | negative(INT a), negative(DOUBLE a) | Returns |
double or int | sign(DOUBLE a), sign(DECIMAL a) | Returns the sign of | |
double | e() | Returns the value of | |
double | pi() | Returns the value of | |
bigint | factorial(INT a) | Returns the factorial of a Valid a is [0..20]. | GenericUDFFactorial |
double | cbrt(DOUBLE a) | Returns the cube root of a double value. | GenericUDFCbrt |
int bigint | shiftleft(TINYINT|SMALLINT|INT a, INT b) shiftleft(BIGINT a, INT b) | Bitwise left shift. Shifts Returns int for tinyint, smallint and int | |
int bigint | shiftright(TINYINT|SMALLINT|INT a, INT b) shiftright(BIGINT a, INT b) | Bitwise right shift. Shifts Returns int for tinyint, smallint and int | |
int bigint | shiftrightunsigned(TINYINT|SMALLINT|INT a, INT b), shiftrightunsigned(BIGINT a, INT b) | Bitwise unsigned right shift. Shifts Returns int for tinyint, smallint and int | |
T | greatest(T v1, T v2, ...) | Returns the greatest value of the list of values. Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with ">" operator. | GenericUDFGreatest |
T | least(T v1, T v2, ...) | Returns the least value of the list of values. Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with "<" operator. | GenericUDFLeast |
int | width_bucket(NUMERIC expr, NUMERIC min_value, NUMERIC max_value, INT num_buckets) | Returns an integer between 0 and num_buckets+1 by mapping expr into the ith equally sized bucket. Buckets are made by dividing [min_value, max_value] into equally sized regions. If expr < min_value, return 1, if expr > max_value return num_buckets+1. See https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions214.htm |
Collection Functions
The following built-in collection functions are supported in Hive.
Return Type | Name(Signature) | Description |
---|---|---|
int | size(Map<K.V>) | Returns the number of elements in the map type. |
int | size(Array<T>) | Returns the number of elements in the array type. |
array<K> | map_keys(Map<K.V>) | Returns an unordered array containing the keys of the input map. |
array<V> | map_values(Map<K.V>) | Returns an unordered array containing the values of the input map. |
boolean | array_contains(Array<T>, value) | Returns TRUE if the array contains the provided paramter parameter value. |
array<t> | sort_array(Array<T>) | Sorts the input array in ascending order according to the natural ordering of the array elements and returns it. |
...
Return Type | Name(Signature) | Description |
---|---|---|
string | mask(string str[, string upper[, string lower[, string number]]]) | Returns a masked version of str. By default, upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". Example: mask("abcd-EFGH-8765-4321") results in xxxx-XXXX-nnnn-nnnn. You can override the characters used in the mask by supplying additional arguments: the second argument controls the mask character for upper case letters, the third argument for lower case letters, and the fourth argument for numbers. For example, mask("abcd-EFGH-8765-4321", "U", "l", "#") results in llll-UUUU-####-####. |
string | mask_first_n(string str[, int n]) | Returns a masked version of str with the first n values masked. Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_first_n("1234-5678-8765-4321", 4) results in nnnn-5678-8765-4321. |
string | mask_last_n(string str[, int n]) | Returns a masked version of str with the last n values masked. Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_last_n("1234-5678-8765-4321", 4) results in 1234-5678-8765-nnnn. |
string | mask_show_first_n(string str[, int n]) | Returns a masked version of str, showing the first n characters unmasked. Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_show_first_n("1234-5678-8765-4321", 4) results in 1234-nnnn-nnnn-nnnn. |
string | mask_show_last_n(string str[, int n]) | Returns a masked version of str, showing the last n characters unmasked. Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_show_last_n("1234-5678-8765-4321", 4) results in nnnn-nnnn-nnnn-4321. |
string | mask_hash(string|char|varchar str) | Returns a hashed value based on str. The hash is consistent and can be used to join masked values together across tables. This function returns null for non-string types. |
...
In Hive several built-in functions do not belong to any categories above. These are the special functions that Hive has.
Return Type | Name(Signature) | Description |
---|---|---|
varies | java_method(class, method[, arg1[, arg2..]]) | Synonym for |
varies | reflect(class, method[, arg1[, arg2..]]) | Calls a Java method by matching the argument signature, using reflection. See Reflect (Generic) UDF for examples. |
int | hash(a1[, a2...]) | Returns a hash value of the arguments. |
string | current_user() | Returns current user name from the configured authenticator manager. Could be the same as the user provided when connecting, but with some authentication managers (for example HadoopDefaultAuthenticator) it could be different. |
string | logged_in_user() | Returns the current user name from the session state. This is the username provided when connecting to Hive. |
string | current_database() | Returns current database name. |
string | md5(string/binary) | Calculates an MD5 128-bit checksum for the string or binary. The value is returned as a string of 32 hex digits, or NULL if the argument was NULL. Example: md5('ABC') = '902fbdd2b1df0c4f70b4a5d23525e932'. |
string | sha1(string/binary) sha(string/binary) | Calculates the SHA-1 digest for string or binary and returns the value as a hex string. Example: sha1('ABC') = '3c01bdbb26f358bab27f267924aa2c9a03fcfdb8'. |
bigint | crc32(string/binary) | Computes a cyclic redundancy check value for string or binary argument and returns bigint value. Example: crc32('ABC') = 2743272264. |
string | sha2(string/binary, int) | Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512). The first argument is the string or binary to be hashed. The second argument indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). SHA-224 is supported starting from Java 8. If either argument is NULL or the hash length is not one of the permitted values, the return value is NULL. Example: sha2('ABC', 256) = 'b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78'. |
binary | aes_encrypt(input string/binary, key string/binary) | Encrypt input using AES. Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: base64(aes_encrypt('ABC', '1234567890123456')) = 'y6Ss+zCYObpCbgfWfyNWTw=='. |
binary | aes_decrypt(input binary, key string/binary) | Decrypt input using AES. Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: aes_decrypt(unbase64('y6Ss+zCYObpCbgfWfyNWTw=='), '1234567890123456') = 'ABC'. |
string | version() | Returns the Hive version. The string contains 2 fields, the first being a build number and the second being a build hash. Example: "select version();" might return "2.1.0.2.5.0.0-1245 r027527b9c5ce1a3d7d0b6d2e6de2378fb0c39232". Actual results will depend on your build. |
bigint | surrogate_key([write_id_bits, task_id_bits]) | Automatically generate numerical Ids for rows as you enter data into a table. Can only be used as default value for acid or insert-only tables. |
Geospatial Statuscolour Green title New
colour | Green |
---|---|
title | New |
...
ESRI UDF's is an extensive list. In Hive documentation we do not replicate all the function documentation. On this link, you can find ESRI UDFs documentation.
...