類型轉化函數
傳回類型 | 函數 | 說明 |
指定“Type” | cast(expr as <Type>) | 類型轉換。例如将字元“1”轉化為整數:cast('1' as bigint),如果轉化失敗傳回NULL |
條件函數
傳回類型 | 函數 | 說明 |
T | if(boolean testCondition, T valueTrue, T valueFalseorNull) | 判斷是否滿足條件,滿足傳回第一個值,否則傳回另外一個值 |
T | coalesce(T v1, T v2, ...) | 傳回一組資料中,第一個不為null的值,如果都為null,則傳回null |
T | case a when b then c[when d then e] else f end | 當a=b,c;當a=d,e;否則f |
T | case when a then b [when c then d] then e end | 當a時傳回b,當c時傳回d,否則為e |
内置表生成函數
傳回類型 | 函數 | 說明 |
數組 | explode(Array<TYPE> a) | 數組一條記錄中有多個參數,将多個參數拆分,每個參數生成一列 |
json_tuple |
explode示範
數組 | SQL | 傳回 |
myCol[1,2] [3,4] | select explode(myCol) as myNewCol from myTable | myNewCol 1 2 3 4 |
字元串函數
傳回類型 | 函數 | 說明 |
int | length(string A) | 傳回字元串的長度 |
string | reverse(string A) | 傳回倒序字元串 |
string | concat(string A, string B…) | 連接配接多個字元串,合并為一個字元串,可以接受任意數量的輸入字元串 |
string | concat_ws(string SEP, string A, string B…) | 連結多個字元串,字元串之間以指定的分隔符分開。 |
string | substr(string A, int start) substring(string A, int start) | 從文本字元串中指定的起始位置後的字元。 |
string | substr(string A, int start, int len) substring(string A, int start, int len) | 從文本字元串中指定的位置指定長度的字元。 |
string | upper(string A) ucase(string A) | 将文本字元串轉換成字母全部大寫形式 |
string | lower(string A) lcase(string A) | 将文本字元串轉換成字母全部小寫形式 |
string | trim(string A) | 删除字元串兩端的空格,字元之間的空格保留 |
string | ltrim(string A) | 删除字元串左邊的空格,其他的空格保留 |
string | rtrim(string A) | 删除字元串右邊的空格,其他的空格保留 |
string | regexp_replace(string A, string B, string C) | 字元串A中的B字元被C字元替代 |
string | regexp_extract(string subject, string pattern, int index) | 通過下标傳回正規表達式指定的部分。regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 2) returns ‘bar.’ |
string | parse_url(string urlString, string partToExtract [, string keyToExtract]) | 傳回URL指定的部分。parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1′, ‘HOST’) 傳回:’facebook.com’ |
string | get_json_object(string json_string, string path) | select a.timestamp, get_json_object(a.appevents, ‘$.eventid’), get_json_object(a.appenvets, ‘$.eventname’) from log a; |
string | space(int n) | 傳回指定數量的空格 |
string | repeat(string str, int n) | 重複N次字元串 |
int | ascii(string str) | 傳回字元串中首字元的數字值 |
string | lpad(string str, int len, string pad) | 傳回指定長度的字元串,給定字元串長度小于指定長度時,由指定字元從左側填補。 |
string | rpad(string str, int len, string pad) | 傳回指定長度的字元串,給定字元串長度小于指定長度時,由指定字元從右側填補。 |
array | split(string str, string pat) | 将字元串轉換為數組。 |
int | find_in_set(string str, string strList) | 傳回字元串str第一次在strlist出現的位置。如果任一參數為NULL,傳回NULL;如果第一個參數包含逗号,傳回0。 |
array<array<string>> | sentences(string str, string lang, string locale) | 将字元串中内容按語句分組,每個單詞間以逗号分隔,最後傳回數組。 例如sentences(‘Hello there! How are you?’) 傳回:( (“Hello”, “there”), (“How”, “are”, “you”) ) |
array<struct<string,double>> | ngrams(array<array<string>>, int N, int K, int pf) | SELECT ngrams(sentences(lower(tweet)), 2, 100 [, 1000]) FROM twitter; |
array<struct<string,double>> | context_ngrams(array<array<string>>, array<string>, int K, int pf) | SELECT context_ngrams(sentences(lower(tweet)), array(null,null), 100, [, 1000]) FROM twitter; |