Hive Functions: Cheat Sheet
Hive Functions: Cheat Sheet
Contents
Cheat Sheet 1 Creating Functions
Hive Functions 2
3
Mathematical, String, Date, Collection, Text, Conditional
Built-In Aggregates, Built-In Table-Generating Functions
HiveQL provides big data querying capabilities in Hadoop in a dialect very similar to SQL and should be
familiar to anyone used to working with SQL databases. This cheat sheet covers more advanced capabilities
of Hive – specifically creating and using User Defined Functions (UDFs) in Hive, and some of the built in
functions
Additional Resources
Learn to become fluent in Apache Hive with the Hive Language Manual:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual
Try out Qubole Data Service (QDS) for free:
http://www.qubole.com/try
Get in the Hortonworks Sandbox and try out Hadoop with interactive tutorials:
http://hortonworks.com/sandbox
We Do Hadoop
We Do Hadoop
Mathematical Functions
We Do Hadoop
String Functions
We Do Hadoop
Date Functions
Return Type Name (Signature) Description
BIGINT
round(double
a)
Returns
the
rounded
BIGINT
value
of
the
double
DOUBLE
round(double
a,
int
d)
Returns
the
double
rounded
to
d
decimal
places
BIGINT
floor(double
a)
Returns
the
maximum
BIGINT
value
that
is
equal
or
less
than
the
double
BIGINT
ceil(double
a),
ceiling(double
a)
Returns
the
minimum
BIGINT
value
that
is
equal
or
greater
than
the
double
Collection Functions
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
value
Sorts
the
input
array
in
ascending
order
according
to
the
natural
ordering
of
array<t>
sort_array(Array<T>)
the
array
elements
and
returns
it
(as
of
version
0.9.0)
Conditional Functions
Return Type Name (Signature) Description
if(boolean
testCondition,
T
valueTrue,
T
Return
valueTrue
when
testCondition
is
true,
returns
valueFalseOrNull
T
valueFalseOrNull)
otherwise
T
COALESCE(T
v1,
T
v2,
...)
Return
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,
return
e;
else
return
f
T
CASE
WHEN
a
THEN
b
[WHEN
c
THEN
d]*
[ELSE
e]
END
When
a
=
true,
returns
b;
when
c
=
true,
return
d;
else
return
e
We Do Hadoop