Professional Documents
Culture Documents
Hive Cheat Sheet - Quick Reference
Hive Cheat Sheet - Quick Reference
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
QUBOLE (HTTP://WWW.QUBOLE.COM/)
PRODUCT (/FEATURES/)
(http://www.qubole.com/)
RESOURCES (HTTP://WWW.QUBOLE.COM/RESOURCES/)
BLOG (HTTP://WWW.QUBOLE.COM/BLOG/)
HELP (/SUPPORT)
LOGIN (HTTPS://API.QUBOLE.COM/USERS/SIGN_IN)
1 of 19
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
import java.util.Date;
import java.text.SimpleDateFormat;
import org.apache.hadoop.hive.ql.exec.UDF;
@Description(name = "YourUDFName",
value = "_FUNC_(InputDataType) - using the input datatype X argument, "+
"returns YYY.",
extended = "Example:\n"
+ " > SELECT _FUNC_(InputDataType) FROM tablename;")
public class YourUDFName extends UDF{
..
public YourUDFName( InputDataType InputValue ){
..;
}
public String evaluate( InputDataType InputValue ){
..;
}
}
Date Functions
The following built-in date functions are supported in hive:
Return
Ty p e
2 of 19
N a m e ( S i g n a t u re )
Example
25/04/15 2:22 pm
Return
Ty p e
3 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
N a m e ( S i g n a t u re )
Example
string
from_unixtime(bigint unixtime[,
string format])
bigint
unix_timestamp()
bigint
unix_timestamp(string date)
bigint
unix_timestamp(string date,
string pattern)
string
to_date(string timestamp)
int
year(string date)
int
month(string date)
int
day(string date)
dayofmonth(date)
int
hour(string date)
int
minute(string date)
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
Return
Ty p e
N a m e ( S i g n a t u re )
Example
int
second(string date)
int
weekofyear(string date)
int
string
string
timestamp
from_utc_timestamp(timestamp,
string timezone)
timestamp
to_utc_timestamp(timestamp,
string timezone)
Mathematical Functions
The following built-in mathematical functions are supported in hive; most return NULL when the argument(
are NULL:
4 of 19
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
BIGINT
round(double a)
DOUBLE
round(double a, int d)
BIGINT
oor(double a)
BIGINT
25/04/15 2:22 pm
5 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
double
double
exp(double a)
double
ln(double a)
double
log10(double a)
double
log2(double a)
double
double
Return ap
double
sqrt(double a)
string
bin(BIGINT a)
string
hex(BIGINT a) hex(string a)
string
unhex(string a)
string
double
abs(double a)
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
int double
pmod(int a, int b)
pmod(double a, double b)
double
sin(double a)
double
asin(double a)
double
cos(double a)
double
acos(double a)
tan(double
a)
tan(double a)
double
atan(double a)
double
degrees(double a)
double
radians(double a)
int double
Returns a
int double
negative(int a),
negative(double a)
Returns -a
oat
sign(double a)
double
e()
double
pi()
String Functions
The following are built-in String functions are supported in hive:
6 of 19
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
int
ascii(string str)
25/04/15 2:22 pm
7 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
string
concat(string|binary A,
string|binary B)
array<struct<string,double>>
context_ngrams(array<array>,
array, int K, int pf)
string
string
int
string
format_number(number x, int
d)
25/04/15 2:22 pm
8 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
string
get_json_object(string
json_string, string path)
boolean
int
int
length(string A)
int
string
lower(string A) lcase(string A)
string
string
ltrim(string A)
25/04/15 2:22 pm
9 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
array<struct<string,double>>
string
parse_url(string urlString,
string partToExtract [, string
keyToExtract])
string
25/04/15 2:22 pm
10 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
string
regexp_extract(string subject,
string pattern, int index)
string
regexp_replace(string
INITIAL_STRING, string
PATTERN, string
REPLACEMENT)
string
string
reverse(string A)
string
25/04/15 2:22 pm
11 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
string
rtrim(string A)
array<array>
string
space(int n)
array
map<string,string>
str_to_map(text[, delimiter1,
delimiter2])
string
substr(string|binary A, int
start) substring(string|binary
A, int start)
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
string
substr(string|binary A, int
start, int len)
substring(string|binary A, int
start, int len)
string
string
trim(string A)
string
upper(string A) ucase(string
A)
Collection Functions
The following built-in collection functions are supported in hive:
12 of 19
Return
Ty p e
N a m e ( S i g n a t u re )
Example
int
size(Map)
int
size(Array)
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
Return
Ty p e
N a m e ( S i g n a t u re )
Example
array
map_keys(Map)
array
map_values(Map)
boolean
array_contains(Array,
value)
array
sort_array(Array)
13 of 19
N a m e ( S i g n a t u re )
Example
bigint
count(*), count(expr),
count(DISTINCT expr[,
expr_.])
double
double
double
min(col)
double
max(col)
25/04/15 2:22 pm
14 of 19
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
Return
Ty p e
N a m e ( S i g n a t u re )
Example
double
variance(col), var_pop(col)
double
var_samp(col)
double
stddev_pop(col)
double
stddev_samp(col)
double
covar_pop(col1, col2)
double
covar_samp(col1, col2)
double
corr(col1, col2)
double
percentile(BIGINT col, p)
array
percentile(BIGINT col,
array(p1 [, p2]))
25/04/15 2:22 pm
Return
Ty p e
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
N a m e ( S i g n a t u re )
Example
double
percentile_approx(DOUBLE
col, p [, B])
array
percentile_approx(DOUBLE
col, array(p1 [, p2]) [, B])
array
histogram_numeric(col, b)
array
collect_set(col)
N a m e ( S i g n a t u re )
inline(ARRAY<STRUCT[,STRUCT]>)
Explode
Conditional Functions
15 of 19
25/04/15 2:22 pm
Return
Ty p e
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
N a m e ( S i g n a t u re )
Example
if(boolean testCondition, T
valueTrue, T valueFalseOrNull)
16 of 19
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
array<struct<string,double>>
context_ngrams(array<array>,
array, int K, int pf)
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
R e t u r n Ty p e
N a m e ( S i g n a t u re )
Example
array<struct<string,double>>
ngrams(array<array>, int N,
int K, int pf)
10
Google +
17 of 19
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
YD World
Contact Form
Full Name
-Please Select-
Result
Contact Us
Company
Contact Info
Home (/)
QUBOLE
About Us (http://www.qubole.com
/about-us/)
Contact Us (http://www.qubole.com
/contact-us/)
Pricing (http://www.qubole.com/pricing/)
Career (http://www.qubole.com/career/)
Quick Start Guides (http://docs.qubole.com
/en/latest/quick-start-guide/index.html)
Product Documentation
(https://www.facebook.com
(http://www.linkedin.com
(https://twitter.com
/qubole)
/company
/@qubole)
/qubole)
(http://docs.qubole.com/en/latest/)
18 of 19
25/04/15 2:22 pm
http://www.qubole.com/resources/cheatsheet/hive-function-ch...
API Documentation
(http://docs.qubole.com/en/latest/restapi/index.html)
Privacy Policy (http://www.qubole.com
/privacy-policy/)
What is Hadoop? (/resources/articles/whatis-hadoop/)
19 of 19
25/04/15 2:22 pm