...
Operator | Operand types | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1714fcbd86ac7295-45b9a218-4ca14ce5-b7c28823-4dc2deee5c91250cf5b5ed5d"><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="9a69732794573a4a-15e412cc-4922478f-85e89286-caa806b3cc0d7f954c6c0287"><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 | ||
---|---|---|---|---|
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 | ||
double | rand(), rand(int seed) | Returns a random number (that changes from row to row) that is distributed uniformly from 0 to 1. Specifiying the seed will make sure the generated random number sequence is deterministic. | ||
double | exp(double a) | Returns ea where e is the base of the natural logarithm | ||
double | ln(double a) | Returns the natural logarithm of the argument | ||
double | log10(double a) | Returns the base-10 logarithm of the argument | ||
double | log2(double a) | Returns the base-2 logarithm of the argument | ||
double | log(double base, double a) | Return the base "base" logarithm of the argument | ||
double | pow(double a, double p) power(double a, double p) | Return ap | ||
double | sqrt(double a) | Returns the square root of a | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5db53196d7ecf8d1-2fdf9efa-406b4844-8fb58fef-6c9cc51d00aefc7c751dca6f"><ac:plain-text-body><![CDATA[ | string | bin(BIGINT a) | Returns the number in binary format (see [[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_bin]]) | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9003be53df048fab-91475c28-48f44296-a4899ae5-757d28e4a9a1cdd75bfa0400"><ac:plain-text-body><![CDATA[ | string | hex(BIGINT a) hex(string a) | If the argument is an int, hex returns the number as a string in hex format. Otherwise if the number is a string, it converts each character into its hex representation and returns the resulting string. (see [[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_hex]]) | ]]></ac:plain-text-body></ac:structured-macro> |
string | unhex(string a) | Inverse of hex. Interprets each pair of characters as a hexidecimal number and converts to the character represented by the number. | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="357978c52fa0996d-2c636470-4a5b43a9-bdb794a6-f4449174ec2fd9db4cf78f84"><ac:plain-text-body><![CDATA[ | string | conv(BIGINT num, int from_base, int to_base) | Converts a number from a given base to another (see [[http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_conv]]) | ]]></ac:plain-text-body></ac:structured-macro> |
double | abs(double a) | Returns the absolute value | ||
int double | pmod(int a, int b) pmod(double a, double b) | Returns the positive value of a mod b | ||
double | sin(double a) | Returns the sine of a (a is in radians) | ||
double | asin(double a) | Returns the arc sin of x if -1<=a<=1 or null otherwise | ||
double | cos(double a) | Returns the cosine of a (a is in radians) | ||
double | acos(double a) | Returns the arc cosine of x if -1<=a<=1 or null otherwise | ||
double | tan(double a) | Returns the tangent of a (a is in radians) | ||
double | atan(double a) | Returns the arctangent of a | ||
double | degrees(double a) | Converts value of a from radians to degrees | ||
double | radians(double a) | Converts value of a from degrees to radians | ||
int double | positive(int a) positive(double a) | Returns a | ||
int double | negative(int a) negative(double a) | Returns -a | ||
float | sign(double a) | Returns the sign of a as '1.0' or '-1.0' | ||
double | e() | Returns the value of e | ||
double | pi() | Returns the value of pi |
...
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 |
Type Conversion Functions
The following type conversion functions are supported in hive:
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 |
Type Conversion Functions
The following type conversion functions are supported in hive:
Return Type | Name(Signature) | Description |
---|---|---|
Expected " | ||
Return Type | Name(Signature) | Description |
Expected "=" to follow "type" | cast(expr as <type>) | Converts the results of the expression expr to <type> e.g. cast('1' as BIGINT) will convert the string '1' to it integral representation. A null is returned if the conversion does not succeed. |
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="daa0d1a15fb95ab6-6e769ea1-4e3e4589-a564ad73-7ccfd392ce598e6adf379e1b"><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="4a3d0d6d22b93071-abe7486c-4afa4379-b0daaf87-a80da306ee4cc7b9ee4ae03c"><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 | ||
int | date_add(string startdate, int days) | Add a number of days to startdate: date_add('2008-12-31', 1) = '2009-01-01' | ||
int | date_sub(string startdate, int days) | Subtract a number of days to startdate: date_sub('2008-12-31', 1) = '2008-12-30' |
...
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="fc29fc1e6aab32b1-8247b68e-4c7f4ae3-8138870b-955bf4f3bcf82252bd6b0245"><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="95778c43e51aa1aa-f72c9d1c-45ee49a1-b733950b-6a9d383e991a62e8274dbcea"><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 | length(string A) | Returns the length of the string | ||
string | reverse(string A) | Returns the reversed string | ||
string | concat(string A, string B...) | Returns the string resulting from concatenating the strings 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. | ||
string | concat_ws(string SEP, string A, string B...) | Like concat() above, but with custom separator SEP. | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eef69ca5d218dfa4-24b586b5-4d6044c9-972f9b67-bbc766f1c99582d6d43fc5f6"><ac:plain-text-body><![CDATA[ | string | substr(string A, int start) substring(string A, int start) | Returns the substring 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="c26312a73058a966-331a2755-4d064ee9-9853a6d8-24707413f29e7fa914eb3ef4"><ac:plain-text-body><![CDATA[ | string | substr(string A, int start, int len) substring(string A, int start, int len) | Returns the substring 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 | 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' | ||
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 | trim(string A) | Returns the string resulting from trimming spaces from both ends of A e.g. trim(' foobar ') results in 'foobar' | ||
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 ' | ||
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' | ||
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 | 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; ' | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5046ba049e290773-a873a210-4a724ca6-978c9b0b-b34da46831ab46039f179d42"><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> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a5b328c63f6ff8b6-e88eadf9-407d4814-98c1ae88-1be9081baeabfd5ae5167504"><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> |
string | space(int n) | Return a string of n spaces | ||
string | repeat(string str, int n) | Repeat str n times | ||
int | ascii(string str) | Returns the numeric value of the first character of str | ||
string | lpad(string str, int len, string pad) | Returns str, left-padded with pad to a length of len | ||
string | rpad(string str, int len, string pad) | Returns str, right-padded with pad to a length of len | ||
array | split(string str, string pat) | Split str around pat (pat is a regular expression) | ||
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 | ||
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") ) | ||
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. | ||
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. | ||
boolean | in_file(string str, string filename) | Returns true if the string str appears as an entire line in filename. |
Misc. Functions
xpath
The following functions are described in LanguageManual XPathUDF:
- xpath, xpath_short, xpath_int, xpath_long, xpath_float, xpath_double, xpath_number, xpath_string
get_json_object
A limited version of JSONPath is supported:
- $ : Root object
- . : Child operator
Wiki Markup \[\] : Subscript operator for array
Wiki Markup \* : Wildcard for \[\]
Syntax not supported that's worth noticing:
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d3a95693-5305-41ec-a622-8344de8f1f4b"><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> |
int | instr(string str, string substr) | Returns the position of the first occurence of substr in str | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="49eeb9ba-361f-4134-a1b9-94b5dcc6e39c"><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> |
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") ) | ||
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. | ||
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. | ||
boolean | in_file(string str, string filename) | Returns true if the string str appears as an entire line in filename. |
Misc. Functions
xpath
The following functions are described in LanguageManual XPathUDF:
- xpath, xpath_short, xpath_int, xpath_long, xpath_float, xpath_double, xpath_number, xpath_string
get_json_object
A limited version of JSONPath is supported:
- $ : Root object
- . : Child operator
Wiki Markup \[\] : Subscript operator for array
Wiki Markup \* : Wildcard for \[\]
Syntax not supported that's worth noticing:
- : Zero length string as key
- .. : Recursive descent
- @ : Current object/element
- () : Script expression
- ?() :
- : Zero length string as key
- .. : Recursive descent
- @ : Current object/element
- () : Script expression
- ?() : Filter (script) expression.
Wiki Markup \[,\] : Union operator
Wiki Markup \[start:end.step\] : array slice operator
...
Return Type | Name(Signature) | Description | ||
---|---|---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="69d169dd27a6b79c-81cb49b9-45ec4dcf-a7428eb0-c668f85fa7930b552a23f755"><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="ba06b0c318e48ca2-1272a115-4ed140a5-8155bc99-d3ebc5efbd017b0477750fff"><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="88a13879bab71d83-652ac2c1-4228469c-932a9a0e-43bc580b453d947213ad4689"><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="d9fcc2669e1296f9-e008c2d4-4d804fd5-ac698a23-ab7fd53accf94c43e9997f0c"><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 |
...
Array<int> myCol | ||
---|---|---|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="53feb9d12e5c2934-9dc11559-40d64825-b8d8ad29-3ed851411eb71e2bae023e01"><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="bfe37152-1944-4a7d-b086-ceeb07420540"><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:
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.
For example,
Code Block |
---|
select a.timestamp, get_json_object(a.appevents, '$.eventid'), get_json_object(a.appenvets, '$.eventname') from log a;
|
should be changed to
"59618939-b874-47c7-8ca3-64435d638240"><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:
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.
For example,
Code Block |
---|
select a.timestamp, get_json_object(a.appevents, '$.eventid'), get_json_object(a.appenvets, '$.eventname') from log a;
|
should be changed to
Code Block |
---|
select a.timestamp, b.*
from log a lateral view json_tuple(a.appevent, 'eventid', 'eventname') b as f1, f2;
|
parse_url_tuple
The parse_url_tuple() UDTF is similar to parse_url(), but can extract multiple parts of a given URL, returning the data in a tuple. Values for a particular key in QUERY can be extracted by appending a colon and the key to the partToExtract argument, e.g. parse_url_tuple('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY:k1', 'QUERY:k2') returns a tuple with values of 'v1','v2'. This is more efficient than calling parse_url() multiple times. All the input parameters and output column types are string.
Code Block |
---|
SELECT b.*
FROM src LATERAL VIEW parse_url_tuple(fullurl, 'HOST', 'PATH', 'QUERY', 'QUERY:id') b as host, path, query, query_id LIMIT 1 |
Code Block |
select a.timestamp, b.*
from log a lateral view json_tuple(a.appevent, 'eventid', 'eventname') b as f1, f2;
|
GROUPing and SORTing on f(column)
...