Versions Compared

Key

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

...

The following built-in type conversion functions are supported in Hive. 

Return Type

Name(Signature)

Description

binary

binary(string|binary)

Casts the parameter into a binary.

Expected "=" to follow "type"

cast(expr as <type>)

Converts the results of the expression expr to <type>. For example, cast('1' as BIGINT) will convert the string '1' to its integral representation. A null is returned if the conversion does not succeed. If cast(expr as boolean) Hive returns true for a non-empty string.

Conditional Functions

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

Return Type

Name(Signature)

Description

T

if(boolean testCondition, T valueTrue, T valueFalseOrNull)

Returns valueTrue when testCondition is true, returns valueFalseOrNull otherwise.

booleanisnull( a )Returns true if a is NULL and false otherwise.
booleanisnotnull ( a )Returns true if a is not NULL and false otherwise.
Tnvl(T value, T default_value)Returns default value if value is null else returns value.

T

COALESCE(T v1, T v2, ...)

Returns the first v that is not NULL, or NULL if all v's are NULL.

T

CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

When a = b, returns c; when a = d, returns e; else returns f.

T

CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

When a = true, returns b; when c = true, returns d; else returns e.

Tnullif( a, b )

Returns NULL if a=b; otherwise returns a.

Tip
titleShorthand for

CASE WHEN a = b then NULL else a


voidassert_true(boolean condition)Throw an exception if 'condition' is not true, otherwise return null. For example, select assert_true (2<1).


Data Masking Functions


Misc. Functions

...

UDFs can be divided into three types depending on the number of input rows and the number of output rows returned. Each of these UDFs needs to derive (implement) a different interface.


UDFUDAFUDTF
It is a function that receives only a single row as an input and returns a single row as an output.
Like: length, or round functions
Extend class: UDF
It is a function that receives multiple rows as input and returns a single row as output.
Like: Count, Min, Max

It is a function that receives a single row as input and returns multiple rows - result set or table - as output.
Like: exploed, parse_url_tuple