...
Operator | Operand types | Description | |||
---|---|---|---|---|---|
A = B | All primitive types | TRUE if expression A is equal to expression B otherwise FALSE | |||
A <=> B | All primitive types | Returns same result with EQUAL(=) operator for non-null operands, but returns TRUE if both are NULL, FALSE if one of the them is NULL (as of version 0.9.0) | |||
A == B | None! | Fails because of invalid syntax. SQL uses =, not == | |||
A <> B | All primitive types | NULL if A or B is NULL, TRUE if expression A is NOT equal to expression B otherwise FALSE | |||
A != B | All primitive types | a synonym for the <> operator | |||
A < B | All primitive types | NULL if A or B is NULL, TRUE if expression A is less than expression B otherwise FALSE | |||
A <= B | All primitive types | NULL if A or B is NULL, TRUE if expression A is less than or equal to expression B otherwise FALSE | |||
A > B | All primitive types | NULL if A or B is NULL, TRUE if expression A is greater than expression B otherwise FALSE | |||
A >= B | All primitive types | NULL if A or B is NULL, TRUE if expression A is greater than or equal to expression B otherwise FALSE | |||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2f92d4d27fefedc4-e0bef69a-4ef744dc-9a7c9d31-69753e1ff2233675f88bb99b"><ac:plain-text-body><![CDATA[ | A [NOT] BETWEEN B AND C | All primitive types | NULL if A, B or C is NULL, TRUE if A is greater than or equal to B AND A less than or equal to C otherwise FALSE. This can be inverted by using the NOT keyword. (as of version [0.9.0 | https://issues.apache.org/jira/browse/HIVE-2005]) | ]]></ac:plain-text-body></ac:structured-macro> |
A IS NULL | all types | TRUE if expression A evaluates to NULL otherwise FALSE | |||
A IS NOT NULL | All types | FALSE if expression A evaluates to NULL otherwise TRUE | |||
A NOT LIKE B | strings | NULL if A or B is NULL, TRUE if string A matches the SQL simple regular expression B, otherwise FALSE. The comparison is done character by character. The _ character in B matches any character in A(similar to . in posix regular expressions) while the % character in B matches an arbitrary number of characters in A(similar to .* in posix regular expressions) e.g. 'foobar' like 'foo' evaluates to FALSE where as 'foobar' like 'foo_ _ _' evaluates to TRUE and so does 'foobar' like 'foo%' | |||
A RLIKE B | strings | NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java regular expression B, otherwise FALSE. E.g. 'foobar' RLIKE 'foo' evaluates to TRUE and so does 'foobar' RLIKE '^f.*r$'. | |||
A REGEXP B | strings | Same as RLIKE |
...
Operator | Operand types | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2ec71ee0d89fcbb5-97feccec-406c4603-bec38c2c-92eb4884ba155042ab537b4a"><ac:plain-text-body><![CDATA[ | A[n] | A is an Array and n is an int | Returns the nth element in the array A. The first element has index 0 e.g. if A is an array comprising of ['foo', 'bar'] then A[0] returns 'foo' and A[1] returns 'bar' | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e73aec42d01381a8-4c45c376-488d4071-9badac61-3bf82a2b7347b05f985365ad"><ac:plain-text-body><![CDATA[ | M[key] | M is a Map<K, V> and key has type K | Returns the value corresponding to the key in the map e.g. if M is a map comprising of {'f' -> 'foo', 'b' -> 'bar', 'all' -> 'foobar'} then M['all'] returns 'foobar' | ]]></ac:plain-text-body></ac:structured-macro> |
S.x | S is a struct | Returns the x field of S. e.g for struct foobar {int foo, int bar} foobar.foo returns the integer stored in the foo field of the struct. |
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="358326d461f49639-689b0ff0-45434610-8a36bcd6-834d6767afde196c52f55dd8"><ac:plain-text-body><![CDATA[ | string | from_unixtime(bigint unixtime[, string format]) | Converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a string representing the timestamp of that moment in the current system time zone in the format of "1970-01-01 00:00:00" | ]]></ac:plain-text-body></ac:structured-macro> |
bigint | unix_timestamp() | Gets current time stamp using the default time zone. | ||
bigint | unix_timestamp(string date) | Converts time string in format | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ba37d15faf70b363-3700020a-47524012-a812976e-addbf8047b408d9145d31718"><ac:plain-text-body><![CDATA[ | bigint | unix_timestamp(string date, string pattern) | Convert time string with given pattern (see [[http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html]]) to Unix time stamp, return 0 if fail: unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400 | ]]></ac:plain-text-body></ac:structured-macro> |
string | to_date(string timestamp) | Returns the date part of a timestamp string: to_date("1970-01-01 00:00:00") = "1970-01-01" | ||
int | year(string date) | Returns the year part of a date or a timestamp string: year("1970-01-01 00:00:00") = 1970, year("1970-01-01") = 1970 | ||
int | month(string date) | Returns the month part of a date or a timestamp string: month("1970-11-01 00:00:00") = 11, month("1970-11-01") = 11 | ||
int | day(string date) dayofmonth(date) | Return the day part of a date or a timestamp string: day("1970-11-01 00:00:00") = 1, day("1970-11-01") = 1 | ||
int | hour(string date) | Returns the hour of the timestamp: hour('2009-07-30 12:58:59') = 12, hour('12:58:59') = 12 | ||
int | minute(string date) | Returns the minute of the timestamp | ||
int | second(string date) | Returns the second of the timestamp | ||
int | weekofyear(string date) | Return the week number of a timestamp string: weekofyear("1970-11-01 00:00:00") = 44, weekofyear("1970-11-01") = 44 | ||
int | datediff(string enddate, string startdate) | Return the number of days from startdate to enddate: datediff('2009-03-01', '2009-02-27') = 2 | ||
string | date_add(string startdate, int days) | Add a number of days to startdate: date_add('2008-12-31', 1) = '2009-01-01' | ||
string | date_sub(string startdate, int days) | Subtract a number of days to startdate: date_sub('2008-12-31', 1) = '2008-12-30' | ||
timestamp | from_utc_timestamp(timestamp, string timezone) | Assumes given timestamp ist UTC and converts to given timezone (as of Hive 0.8.0) | ||
timestamp | to_utc_timestamp(timestamp, string timezone) | Assumes given timestamp is in given timezone and converts to UTC (as of Hive 0.8.0) |
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
T | if(boolean testCondition, T valueTrue, T valueFalseOrNull) | Return valueTrue when testCondition is true, returns valueFalseOrNull otherwise | ||
T | COALESCE(T v1, T v2, ...) | Return the first v that is not NULL, or NULL if all v's are NULL | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8b94971776cc6d11-273153a6-46704eb4-b064abe9-bd158a03d20a5a9c3d5f46c9"><ac:plain-text-body><![CDATA[ | 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 | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="006ca67de8eef4f3-2849b30b-45cd4f89-bb4c87cf-fd5d7ba4a73e24026e5769e3"><ac:plain-text-body><![CDATA[ | 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 | ]]></ac:plain-text-body></ac:structured-macro> |
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
int | ascii(string str) | Returns the numeric value of the first character of str | ||
string | base64(binary bin) | Convert the argument from binary to a base 64 string (as of Hive 0.12.0) | ||
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. e.g. concat('foo', 'bar') results in 'foobar'. Note that this function can take any number of input strings. | ||
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. | ||
string | concat_ws(string SEP, string A, string B...) | Like concat() above, but with custom separator SEP. | ||
string | concat_ws(string SEP, array<string>) | Like concat_ws() above, but taking an array of strings. (as of Hive 0.9.0) | ||
string | decode(binary bin, string charset) | Decode 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. (as of Hive 0.12.0) | ||
binary | encode(string src, string charset) | Encode 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. (as of Hive 0.12.0) | ||
int | find_in_set(string str, string strList) | Returns the first occurance 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. e.g. find_in_set('ab', 'abc,b,ab,c,def') returns 3 | ||
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. (as of Hive 0.10.0) | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="98bc4ed6ef208af1-bfa5d6d2-45ac4a66-9c0b8ead-2a50ac7e4173f04e8c50e030"><ac:plain-text-body><![CDATA[ | string | get_json_object(string json_string, string path) | Extract json object from a json string based on json path specified, and return json string of the extracted json object. It will return null if the input json string is invalid. NOTE: 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. | ]]></ac:plain-text-body></ac:structured-macro> |
boolean | in_file(string str, string filename) | Returns true if the string str appears as an entire line in filename. | ||
int | instr(string str, string substr) | Returns the position of the first occurence of substr in str | ||
int | length(string A) | Returns the length of the string | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d3b96f0059ae6239-7bd9f0eb-4dbf4a4a-a92dafc3-7fbf701ca1271764babae1a8"><ac:plain-text-body><![CDATA[ | int | locate(string substr, string str[, int pos]) | Returns the position of the first occurrence of substr in str after position pos | ]]></ac:plain-text-body></ac:structured-macro> |
string | lower(string A) lcase(string A) | Returns the string resulting from converting all characters of B to lower case e.g. lower('fOoBaR') results in 'foobar' | ||
string | lpad(string str, int len, string pad) | Returns str, left-padded with pad to a length of len | ||
string | ltrim(string A) | Returns the string resulting from trimming spaces from the beginning(left hand side) of A e.g. ltrim(' foobar ') results in 'foobar ' | ||
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. | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0616458f49935b69-bf13582a-4457401b-8fdd8bc1-e5ed2b1fb226e536988699e6"><ac:plain-text-body><![CDATA[ | 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. e.g. 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, e.g. parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1') returns 'v1'. | ]]></ac:plain-text-body></ac:structured-macro> |
string | printf(String format, Obj... args) | Returns the input formatted according do printf-style format strings (as of Hive 0.9.0) | ||
string | regexp_extract(string subject, string pattern, int index) | Returns the string extracted using the pattern. e.g. 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; ' | ||
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, e.g. 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; ' | ||
string | repeat(string str, int n) | Repeat str n times | ||
string | reverse(string A) | Returns the reversed string | ||
string | rpad(string str, int len, string pad) | Returns str, right-padded with pad to a length of len | ||
string | rtrim(string A) | Returns the string resulting from trimming spaces from the end(right hand side) of A e.g. rtrim(' foobar ') results in ' foobar' | ||
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. e.g. sentences('Hello there! How are you?') returns ( ("Hello", "there"), ("How", "are", "you") ) | ||
string | space(int n) | Return a string of n spaces | ||
array | split(string str, string pat) | Split str around pat (pat is a regular expression) | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9e3ac8e26e0669d1-19a5b0b7-432c41a0-8779a420-638477bd59f246b9699c1131"><ac:plain-text-body><![CDATA[ | 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. | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8ebdcfa975bc6c6f-81caa306-42914a83-94d88751-d65e5c1ce0769d7b7806f89d"><ac:plain-text-body><![CDATA[ | 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 e.g. substr('foobar', 4) results in 'bar' (see [[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr]]) | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8ee7276625a8956b-bd04ab23-4035458b-a2cea0a3-3c1d614970f204147c82d7c3"><ac:plain-text-body><![CDATA[ | 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 e.g. substr('foobar', 4, 1) results in 'b' (see [[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr]]) | ]]></ac:plain-text-body></ac:structured-macro> |
string | translate(string input, string from, string to) | Translates the input string by replacing the characters present in the | ||
string | trim(string A) | Returns the string resulting from trimming spaces from both ends of A e.g. trim(' foobar ') results in 'foobar' | ||
binary | unbase64(string str) | Convert the argument from a base 64 string to BINARY (as of Hive 0.12.0) | ||
string | upper(string A) ucase(string A) | Returns the string resulting from converting all characters of A to upper case e.g. upper('fOoBaR') results in 'FOOBAR' |
...
Return Type | Name(Signature) | Description | |||
---|---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="236e52e7ebc462a7-a96d4096-4ac74327-99e88efd-2804c43dfb20a8f4b3812e99"><ac:plain-text-body><![CDATA[ | varies | java_method(class, method[, arg1[, arg2..]]) | Synonym for | https://issues.apache.org/jira/browse/HIVE-1877]) | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="015cb5b8e3f0be1e-f24b90af-4b2f4916-8c01bdbd-168aaef48a0fd53e5c01cd6a"><ac:plain-text-body><![CDATA[ | varies | reflect(class, method[, arg1[, arg2..]]) | Use this UDF to call Java methods by matching the argument signature (uses reflection). (as of Hive [0.7.0 | https://issues.apache.org/jira/browse/HIVE-471]) | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="95b0b3858615efff-dcb781a8-45a74077-bde3ad30-da9d34988c7212d9691b4839"><ac:plain-text-body><![CDATA[ | int | hash(a1[, a2...]) | Returns a hash value of the arguments (as of Hive 0.4) | ]]></ac:plain-text-body></ac:structured-macro> |
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ca83db7e366330b2-4a4f5cfa-4e37438c-9ea5b607-d1d5fbe3eecfb8fef815a855"><ac:plain-text-body><![CDATA[ | BIGINT | count(*), count(expr), count(DISTINCT expr[, expr_.]) | count(*) - Returns the total number of retrieved rows, including rows containing NULL values; count(expr) - Returns the number of rows for which the supplied expression is non-NULL; count(DISTINCT expr[, expr]) - Returns the number of rows for which the supplied expression(s) are unique and non-NULL. | ]]></ac:plain-text-body></ac:structured-macro> |
DOUBLE | sum(col), sum(DISTINCT col) | Returns the sum of the elements in the group or the sum of the distinct values of the column in the group | ||
DOUBLE | avg(col), avg(DISTINCT col) | Returns the average of the elements in the group or the average of the distinct values of the column in the group | ||
DOUBLE | min(col) | Returns the minimum of the column in the group | ||
DOUBLE | max(col) | Returns the maximum value of the column in the group | ||
DOUBLE | variance(col), var_pop(col) | Returns the variance of a numeric column in the group | ||
DOUBLE | var_samp(col) | Returns the unbiased sample variance of a numeric column in the group | ||
DOUBLE | stddev_pop(col) | Returns the standard deviation of a numeric column in the group | ||
DOUBLE | stddev_samp(col) | Returns the unbiased sample standard deviation of a numeric column in the group | ||
DOUBLE | covar_pop(col1, col2) | Returns the population covariance of a pair of numeric columns in the group | ||
DOUBLE | covar_samp(col1, col2) | Returns the sample covariance of a pair of a numeric columns in the group | ||
DOUBLE | corr(col1, col2) | Returns the Pearson coefficient of correlation of a pair of a numeric columns in the group | ||
DOUBLE | percentile(BIGINT col, p) | Returns the exact pth percentile of a column in the group (does not work with floating point types). p must be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral. | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="738ff5c8d6aabfb7-f5cfcc4e-4f344261-9dde8794-36d39228a5c21e31c64e7e5b"><ac:plain-text-body><![CDATA[ | array<double> | percentile(BIGINT col, array(p1 [, p2]...)) | Returns the exact percentiles p1, p2, ... of a column in the group (does not work with floating point types). pi must be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral. | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a4773bf5e86c22ec-288cee10-4e5c4532-8038b44f-84620a7f7de0517ff5306a23"><ac:plain-text-body><![CDATA[ | DOUBLE | percentile_approx(DOUBLE col, p [, B]) | Returns an approximate pth percentile of a numeric column (including floating point types) in the group. The B parameter controls approximation accuracy at the cost of memory. Higher values yield better approximations, and the default is 10,000. When the number of distinct values in col is smaller than B, this gives an exact percentile value. | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="93e01fbf9e8dfc03-ece3e376-46804cae-a83886e4-104ed516271089296119be84"><ac:plain-text-body><![CDATA[ | array<double> | percentile_approx(DOUBLE col, array(p1 [, p2]...) [, B]) | Same as above, but accepts and returns an array of percentile values instead of a single one. | ]]></ac:plain-text-body></ac:structured-macro> |
array<struct { | histogram_numeric(col, b) | Computes a histogram of a numeric column in the group using b non-uniformly spaced bins. The output is an array of size b of double-valued (x,y) coordinates that represent the bin centers and heights | ||
array | collect_set(col) | Returns a set of objects with duplicate elements eliminated |
...
Normal user-defined functions, such as concat(), take in a single input row and output a single output row. In contrast, table-generating functions transform a single input row to multiple output rows.
Return Type | Name(Signature) | Description | |||
---|---|---|---|---|---|
N rows | explode(ARRAY) | Returns one row for each element from the array | |||
N rows | explode(MAP) | Returns one row for each key-value pair from the input map with two columns in each row: one for the key and another for the value. (as of Hive 0.8.0) | |||
<ac:<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ca2b65034e5f10e6-eba63f20-4dd1440d-9a1d91c2-7677a01ea7cd6e9c52b92ddc"><ac:plain-text-body><![CDATA[ |
| inline(ARRAY<STRUCT[,STRUCT]>) | Explodes an array of structs into a table (as of Hive [0.10 | https://issues.apache.org/jira/browse/HIVE-3238]) | ]]></ac:plain-text-body></ac:structured-macro> |
Array Type | explode(array<TYPE> a) |
explode() takes in an array as an input and outputs the elements of the array as separate rows. UDTF's can be used in the SELECT expression list and as a part of LATERAL VIEW.
An example use of explode() in the SELECT expression list is as follows:
Consider a table named myTable that has a single column (myCol) and two rows:
Array<int> myCol | ||
---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="767a5837-8c10-47ea-85c4-9c8d8195f03a"><ac:plain-text-body><![CDATA[ | [1,2,3] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6316916a-a892-48b3-9e28-ea1a7efd8275"><ac:plain-text-body><![CDATA[ | [4,5,6] | ]]></ac:plain-text-body></ac:structured-macro> |
Then running the query:
SELECT explode(myCol) AS myNewCol FROM myTable;
Will produce:
(int) myNewCol |
---|
1 |
2 |
3 |
4 |
5 |
6 |
Using the syntax "SELECT udtf(col) AS colAlias..." has a few limitations:
- No other expressions are allowed in SELECT
- SELECT pageid, explode(adid_list) AS myCol... is not supported
- UDTF's can't be nested
- SELECT explode(explode(adid_list)) AS myCol... is not supported
- GROUP BY / CLUSTER BY / DISTRIBUTE BY / SORT BY is not supported
- SELECT explode(adid_list) AS myCol ... GROUP BY myCol is not supported
Please see LanguageManual LateralView for an alternative syntax that does not have these limitations.
The following are built-in table-generating functions are supported in Hive:
For each element in a, explode() generates a row containing that element | ||
tuple | json_tuple(jsonStr, k1, k2, ...) | It takes a set of names (keys) and a JSON string, and returns a tuple of values. This is a more efficient version of the |
tuple | parse_url_tuple(url, p1, p2, ...) | This is similar to the |
| stack(INT n, v_1, v_2, ..., v_k) | Breaks up v_1, ..., v_k into n rows. Each row will have k/n columns. n must be constant. |
Using the syntax "SELECT udtf(col) AS colAlias..." has a few limitations:
- No other expressions are allowed in SELECT
- SELECT pageid, explode(adid_list) AS myCol... is not supported
- UDTF's can't be nested
- SELECT explode(explode(adid_list)) AS myCol... is not supported
- GROUP BY / CLUSTER BY / DISTRIBUTE BY / SORT BY is not supported
- SELECT explode(adid_list) AS myCol ... GROUP BY myCol is not supported
Please see LanguageManual LateralView for an alternative syntax that does not have these limitations.
explode
explode() takes in an array as an input and outputs the elements of the array as separate rows. UDTF's can be used in the SELECT expression list and as a part of LATERAL VIEW.
An example use of explode() in the SELECT expression list is as follows:
Consider a table named myTable that has a single column (myCol) and two rows:
Array<int> myCol | ||
---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="98729221-58b9-4aee-985b-2f3830280750"><ac:plain-text-body><![CDATA[ | [1,2,3] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c2f0dd73-1f86-4bb7-8444-aae7101d8076"><ac:plain-text-body><![CDATA[ | [4,5,6] | ]]></ac:plain-text-body></ac:structured-macro> |
Then running the query:
SELECT explode(myCol) AS myNewCol FROM myTable;
Will produce:
(int) myNewCol | ||
---|---|---|
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
Return Type | Name(Signature) | Description |
Array Type | explode(array<TYPE> a) | For each element in a, explode() generates a row containing that element |
| stack(INT n, v_1, v_2, ..., v_k) | Breaks up v_1, ..., v_k into n rows. Each row will have k/n columns. n must be constant. |
json_tuple
A new json_tuple() UDTF is introduced in hive 0.7. It takes a set of names (keys) and a JSON string, and returns a tuple of values using one function. This is much more efficient than calling GET_JSON_OBJECT to retrieve more than one key from a single JSON string. In any case where a single JSON string would be parsed more than once, your query will be more efficient if you parse it once, which is what JSON_TUPLE is for. As JSON_TUPLE is a UDTF, you will need to use the LATERAL VIEW syntax in order to achieve the same goal.
...