Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Return Type

Name(Signature)

Description

OSS

int

ascii(string str)

Returns the numeric value of the first character of str.

UDFAscii

string

base64(binary bin)

Converts the argument from binary to a base64string.

UDFBase64

int
character_length(string str)
Returns the number of UTF-8 characters contained in str. The function char_length is shorthand for this function.GenericUDFCharacterLength
string
chr(bigint|double A)
Returns the ASCII character having the binary equivalent to A. If A is larger than 256 the result is equivalent to chr(A % 256). Example: select chr(88); returns "X".UDFChr

string

concat(string|binary A,string|binary B...)

Returns the string or bytes resulting from concatenating the strings or bytes passed in as parameters in order. For example, concat('foo', 'bar') results in 'foobar'. Note that this function can take any number of input strings.

GenericUDFConcat

array<struct<string,double>>

context_ngrams(array<array<string>>, array<string>, int K, int pf)

Returns the top-k contextual N-grams from a set of tokenized sentences, given a string of "context". See StatisticsAndDataMining for more information.

GenericUDAFContextNGrams

string

concat_ws(string SEP, string A, string B...)

Like concat() above, but with custom separator SEP.


GenericUDFConcatWS

string

concat_ws(string SEP, array<string>)

Like concat_ws() above, but taking an array ofstrings.

string

decode(binary bin, string charset)

Decodes the first argument into a string using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null.

GenericUDFDecode

string
elt(N int, str1 string, str2s tring, str3 string,...)

Return string at index number. For example elt(2,'hello','world') returns 'world'. Returns NULL if N is less than 1 or greater than the number of arguments.

GenericUDFElt

binary

encode(string src, string charset)

Encodes the first argument into a BINARY using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null. 

GenericUDFEncode

int
field(val T, val1 T, val2 T, val3 T,...) 

Returns the index of val in the val1,val2,val3,... list or 0 if not found. For example field('world','say','hello','world') returns 3.
All primitive types are supported, arguments are compared using str.equals(x). If val is NULL, the return value is 0.

GenericUDFField

int

find_in_set(string str, string strList)

Returns the first occurrence of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. For example, find_in_set('ab', 'abc,b,ab,c,def') returns 3.

UDFFindInSet

string

format_number(number x, int d)

Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part.

GenericUDFFormatNumber

string

get_json_object(string json_string,string path)

Extracts JSON object from a JSON string based on JSON path specified, and returns JSON string of the extracted JSON object. It will return null if the input JSON string is invalid.

Note
titleNote

The json path can only have the characters [0-9a-z_], i.e., no upper-case or special characters. Also, the keys *cannot start with numbers.* This is due to restrictions on Hive column names.


boolean

in_file(string str, string filename)

Returns true if the string str appears as an entire line in filename.

GenericUDFInFile

int

instr(string str, string substr)

Returns the position of the first occurrence of substr in str. Returns null if either of the arguments are null and returns 0 if substr could not be found in str. Be aware that this is not zero-based. The first character in str has index 1.

GenericUDFInstr

int

length(string A)

Returns the length of the string.

GenericUDFLength

int

locate(string substr,string str[,int pos])

Returns the position of the first occurrence of substr in str after position pos.

GenericUDFLocate

string

lower(string A) lcase(string A)

Returns the string resulting from converting all characters of B to lowercase. For example, lower('fOoBaR') results in 'foobar'.

GenericUDFLower

string

lpad(string str,int len,string pad)

Returns str, left-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. In the case of an empty padstring, the return value is null.

GenericUDFLpad

string

ltrim(string A)

Returns the string resulting from trimming spaces from the beginning(left-hand side) of A. For example, ltrim(' foobar ') results in 'foobar '.

GenericUDFLTrim

array<struct<string,double>>

ngrams(array<array<string>>,int N,int K,int pf)

Returns the top-k N-grams from a set of tokenized sentences, such as those returned by the sentences() UDAF. See StatisticsAndDataMining for more information.

GenericUDAFnGrams

int
octet_length(string str)
Returns the number of octets required to hold the string str in UTF-8 encoding.  Note that octet_length(str) can be larger than character_length(str).GenericUDFOctetLength

string

parse_url(string urlString,string partToExtract [,string keyToExtract])

Returns the specified part from the URL. Valid values for partToExtract include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. For example, parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'HOST') returns 'facebook.com'. Also, a value of a particular key in QUERY can be extracted by providing the key as the third argument, for example, parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1') returns 'v1'.

UDFParseUrl

string

printf(string format, Obj... args)

Returns the input formatted according to printf-style formatstrings.

GenericUDFPrintf

string
quote(string text)

Returns the quoted string 

InputOutput
NULLNULL
DONT'DONT'
DON'T'DON\'T'

Status
colourGreen
titleNew
Includes escape character for any single quotes in Apache Hive 4.0.0

string

regexp_extract(string subject, string pattern, int index)

Returns the string extracted using the pattern. For example, regexp_extract('foothebar', 'foo(.*?)(bar)', 2) returns 'bar.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc. The 'index' parameter is the Java regex Matcher group() method index. 

UDFRegExpExtract

string

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc.

UDFRegExpReplace

string

repeat(string str, int n)

Repeats str in n times.

UDFRepeat

string
replace(string A, string OLD, string NEW)
Returns the string A with all non-overlapping occurrences of OLD replaced with NEW. Example: select replace("ababab", "abab", "Z"); returns "Zab".UDFReplace

string

reverse(string A)

Returns the reversed string.

UDFReverse

string

rpad(string str,int len,string pad)

Returns str, right-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. In case of empty padstring, the return value is null.

GenericUDFRpad

string

rtrim(string A)

Returns the string resulting from trimming spaces from the end(right hand side) of A. For example, rtrim(' foobar ') results in ' foobar'.

GenericUDFRTrim

array<array<string>>

sentences(string str,string lang,string locale)

Tokenizes a string of natural language text into words and sentences, where each sentence is broken at the appropriate sentence boundary and returned as an array of words. The 'lang' and 'locale' are optional arguments. For example, sentences('Hello there! How are you?') returns ( ("Hello", "there"), ("How", "are", "you") ).

GenericUDFSentences

string

space(int n)

Returns a string of n spaces.

UDFSpace

array

split(string str, string pat)

Splits str around pat (pat is a regular expression).

GenericUDFSplit

map<string,string>

str_to_map(text[, delimiter1, delimiter2])

Splits text into key-value pairs using two delimiters. Delimiter1 separates text into K-V pairs, and Delimiter2 splits each K-V pair. Default delimiters are ',' for delimiter1 and ':' for delimiter2.

GenericUDFStringToMap

string

substr(string|binary A,int start) substring(string|binary A,int start)

Returns the substring or slice of the byte array of A starting from start position till the end of string A. For example, substr('foobar', 4) results in 'bar'.

GenericUDFSubstringIndex



string

substr(string|binary A,int start,int len) substring(string|binary A,int start,int len)

Returns the substring or slice of the byte array of A starting from start position with length len. For example, substr('foobar', 4, 1) results in 'b'.

string
substring_index(string A,string delim,int count)
Returns the substring from string A before count occurrences of the delimiter delim. If the count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. Substring_index performs a case-sensitive match when searching for delim. Example: substring_index('www.apache.org', '.', 2) = 'www.apache'.GenericUDFSubstringIndex

string

translate(string|char|varchar input,string|char|varchar from,string|char|varchar to)

Translates the input string by replacing the characters present in the fromstring with the corresponding characters in the tostring. This is similar to the translate function in PostgreSQL. If any of the parameters to this UDF are NULL, the result is NULL as well. 

GenericUDFTranslate

string

trim(string A)

Returns the string resulting from trimming spaces from both ends of A. For example, trim(' foobar ') results in 'foobar'

GenericUDFTrim

binary

unbase64(string str)

Converts the argument from a base 64string to BINARY.

UDFUnbase64

string

upper(string A) ucase(string A)

Returns the string resulting from converting all characters of A to upper case. For example, upper('fOoBaR') results in 'FOOBAR'.

GenericUDFUpper

string
initcap(string A)
Returns string, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by whitespace.GenericUDFInitCap
int
levenshtein(string A, string B)
Returns the Levenshtein distance between two strings. Example: levenshtein('kitten', 'sitting') results in 3.GenericUDFLevenshtein
string
soundex(string A)
Returns the soundex code of the string. Example: soundex('Miller') results in M460.GenericUDFSoundex

coshReturns the hyperbolic cosine of x, where x is in radians.

Date Functions

In many analytical workloads Date is one of the most used built-in functions in Hive. The following list contains the supported built-in date functions in Hive.

...

Return Type

Name (Signature)

Description

OSS

double

round(double a)

Returns the rounded bigint value of a.

GenericUDFRound

double

round(double a,int d)

Returns a rounded to d decimal places.

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 value that is equal to or less than a.

GenericUDFFloor

bigint

ceil(double a), ceiling(double a)

Returns the minimum bigint value that is equal to or greater than a.

GenericUDFCeil

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.

UDFRand

double

exp(double a), exp(decimal a)

Returns ea where e is the base of the natural logarithm.

UDFExp

double

ln(double a), ln(decimal a)

Returns the natural logarithm of the argument a.

UDFLn

double

log10(double a), log10(decimal a)

Returns the base-10 logarithm of the argument a.

UDFLog10

double

log2(double a), log2(decimal a)

Returns the base-2 logarithm of the argument a

UDFLog2

double

log(double base, double a)
log(decimal base, decimal a)

Returns the base-base logarithm of the argument a.

UDFLog

double

pow(double a, double p), power(double a, double p)

Returns ap.

GenericUDFPower

double

sqrt(double a), sqrt(decimal a)

Returns the square root of a.

UDFSqrt

string

bin(bigint a)

Returns the number in binary format.

UDFBin

string

hex(bigint a) hex(string a) hex(binary a)

If the argument is an int or binary, hex returns the number as a string in hexadecimal format. Otherwise, if the number is a string, it converts each character into its hexadecimal representation and returns the resulting string. 

UDFHex

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.

UDFUnhex

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.

UDFConv

double

abs(double a)

Returns the absolute value.

GenericUDFAbs

int or double

pmod(INT a,int b), pmod(double a, double b)

Returns the positive value of a mod b.

GenericUDFOPMod

double

sin(double a), sin(decimal a)

Returns the sine of a (a is in radians).

UDFSin

double

asin(double a), asin(decimal a)

Returns the arc sin of a if -1<=a<=1 or NULL otherwise

UDFAsin

double

cos(double a), cos(decimal a)

Returns the cosine of a (a is in radians)

UDFCos

double

acos(double a), acos(decimal a)

Returns the arccosine of a if -1<=a<=1 or NULL otherwise.

UDFAcos

double

tan(double a), tan(decimal a)

Returns the tangent of a (a is in radians).

UDFTan

double

atan(double a), atan(decimal a)

Returns the arctangent of a.

UDFAtan

double

degrees(double a), degrees(decimal a)

Converts value of a from radians to degrees

UDFDegrees

double

radians(double a), radians(double a)

Converts value of a from degrees to radians

UDFRadians

int or double

positive(INT a), positive(double a)

Returns a.

GenericUDFOPPositive

int or double

negative(INT a), negative(double a)

Returns -a.

GenericUDFOPNegative

double or int

sign(double a), sign(decimal a)

Returns the sign of a as '1.0' (if a is positive) or '-1.0' (if a is negative), '0.0' otherwise. The decimal version returns int instead of double. 

UDFSign

double

e()

Returns the value of e.

UDFE

double

pi()

Returns the value of pi.

UDFPI

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 a b positions to the left.

Returns int for tinyint, smallint andint a. Returns bigint for bigint a.

UDFOPBitShiftLeft

int

bigint

shiftright(TINYINT|SMALLINT|INT a,int b)
shiftright(bigint a,int b)

Bitwise right shift. Shifts a b positions to the right.

Returns int for tinyint, smallint andint a. Returns bigint for bigint a.

UDFOPBitShiftRight

int

bigint

shiftrightunsigned(TINYINT|SMALLINT|INT a,int b),
shiftrightunsigned(bigint a,int b)

Bitwise unsigned right shift. Shifts a b positions to the right.

Returns int for tinyint, smallint andint a. Returns bigint for bigint a.

UDFOPBitShiftRightUnsigned

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

GenericUDFWidthBucket

double
cosh(double x)

Status
colourGreen
titleNew
Returns the hyperbolic cosine of x, where x is in radians.

UDFCosh

double
tanh(double x)

Status
colourGreen
titleNew
Returns the hyperbolic tangent of x, where x is in radians.



Collection Functions

The following built-in collection functions are supported in Hive. 

...