In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shares with you the content of the sample analysis of Hive UDF. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Hive UDF collates string function numeric string length function: length
Syntax: length (string A)
Return value: int
Description: returns the length of string A
For example:
Hive > select length ('abcedfg') from dual
seven
String inversion function: reverse
Syntax: reverse (string A)
Return value: string
Description: returns the inversion result of the string A
For example:
Hive > select reverse ('abcedfg') from dual
Gfdecba
String concatenation function: concat
Syntax: concat (string A, string B...)
Return value: string
Description: returns the result of the input string connection. Any input string is supported.
For example:
Hive > select concat ('abc','def','gh') from dual
Abcdefgh
Delimited string concatenation function: concat_ws
Syntax: concat_ws (string SEP, string A, string B...)
Return value: string
Description: returns the result after the input string is concatenated. SEP represents the delimiter between each string.
For example:
Hive > select concat_ws (',', 'abc','def','gh') from dual
Abc,def,gh
String interception function: substr,substring
Syntax: substr (string A, int start), substring (string A, int start)
Return value: string
Description: returns the string A from the start position to the end of the string
For example:
Hive > select substr ('abcde',3) from dual
Cde
Hive > select substring ('abcde',3) from dual
Cde
Hive > select substr ('abcde',-1) from dual; (same as ORACLE)
E
String interception function: substr,substring
Syntax: substr (string A, int start, int len), substring (string A, int start, int len)
Return value: string
Description: returns the string A that starts at the start position and has a length of len.
For example:
Hive > select substr ('abcde',3,2) from dual
Cd
Hive > select substring ('abcde',3,2) from dual
Cd
Hive > select substring ('abcde',-2,2) from dual
De
String to uppercase function: upper,ucase
Syntax: upper (string A) ucase (string A)
Return value: string
Description: returns the uppercase format of string A
For example:
Hive > select upper ('abSEd') from dual
ABSED
Hive > select ucase ('abSEd') from dual
ABSED
String to lowercase function: lower,lcase
Syntax: lower (string A) lcase (string A)
Return value: string
Description: returns the lowercase format of string A
For example:
Hive > select lower ('abSEd') from dual
Absed
Hive > select lcase ('abSEd') from dual
Absed
Unspace function: trim
Syntax: trim (string A)
Return value: string
Description: remove spaces on both sides of the string
For example:
Hive > select trim ('abc') from dual
Abc
Go to the left space function: ltrim
Syntax: ltrim (string A)
Return value: string
Description: remove the space on the left side of the string
For example:
Hive > select ltrim ('abc') from dual
Abc
The right-hand space function: rtrim
Syntax: rtrim (string A)
Return value: string
Description: remove the space on the right side of the string
For example:
Hive > select rtrim ('abc') from dual
Abc
Regular expression replacement function: regexp_replace
Syntax: regexp_replace (string A, string B, string C)
Return value: string
Description: replace the part of the string A that conforms to the java regular expression B with C. Note that escape characters are used in some cases
For example:
Hive > select regexp_replace ('foobar',' oo | ar', ") from dual
Fb
Regular expression parsing function: regexp_extract
Syntax: regexp_extract (string subject, string pattern, int index)
Return value: string
Description: splits the string subject according to the rules of pattern regular expressions and returns the characters specified by index. Note that escape characters are used in some cases
For example:
Hive > select regexp_extract ('foothebar',' foo (. *?) (bar)', 1) from dual
The
Hive > select regexp_extract ('foothebar',' foo (. *?) (bar)', 2) from dual
Bar
Hive > select regexp_extract ('foothebar',' foo (. *?) (bar)', 0) from dual
Foothebar
URL analytic function: parse_url
Syntax: parse_url (string urlString, string partToExtract [, string keyToExtract])
Return value: string
Description: returns the specified part of the URL. The valid values of partToExtract are: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO.
For example:
Hive > select parse_url ('http://facebook.com/path2/p.php?k1=v1&k2=v2#Ref1 boys,' HOST') from dual
Facebook.com
Hive > select parse_url ('http://facebook.com/path2/p.php?k1=v1&k2=v2#Ref1 boys,' QUERY', 'K1') from dual
V1
Json analytic function: get_json_object
Syntax: get_json_object (string json_string, string path)
Return value: string
Description: parses the string json_string of json and returns the content specified by path. If the json string entered is not valid, NULL is returned.
For example:
Hive > select get_json_object ('{"store":
> {"fruit":\ [{"weight": 8, "type": "apple"}, {"weight": 9, "type": "pear"}]
> "bicycle": {"price": 19.95, "color": "red"}
>}
> "email": "amy@only_for_json_udf_test.net"
> "owner": "amy"
>}
>','$.owner') from dual
Amy
Space string function: space
Syntax: space (int n)
Return value: string
Description: returns a string of length n
For example:
Hive > select space (10) from dual
Hive > select length (space (10)) from dual
ten
Repeating string function: repeat
Syntax: repeat (string str, int n)
Return value: string
Description: returns the str string repeated n times
For example:
Hive > select repeat ('abc',5) from dual
Abcabcabcabcabc
First character ascii function: ascii
Syntax: ascii (string str)
Return value: int
Description: returns the ascii code of the first character of the string str
For example:
Hive > select ascii ('abcde') from dual
ninety-seven
Left complement function: lpad
Syntax: lpad (string str, int len, string pad)
Return value: string
Description: use pad to complete str to Lenn bit
For example:
Hive > select lpad ('abc',10,'td') from dual
Tdtdtdtabc
Unlike GP,ORACLE, pad cannot default
Right complement function: rpad
Syntax: rpad (string str, int len, string pad)
Return value: string
Description: right complement of str to Lenn bit with pad
For example:
Hive > select rpad ('abc',10,'td') from dual
Abctdtdtdt
Split string function: split
Syntax: split (string str, string pat)
Return value: array
Note: split the str according to the pat string and return the split string array.
For example:
Hive > select split ('abtcdtef','t') from dual
["ab", "cd", "ef"]
Collection lookup function: find_in_set
Syntax: find_in_set (string str, string strList)
Return value: int
Description: returns the position where str first appeared in strlist. Strlist is a string separated by commas. If the str character is not found, 0 is returned (can only be separated by commas, otherwise 0 is returned)
For example:
Hive > select find_in_set ('ab','ef,ab,de') from dual
two
Hive > select find_in_set ('at','ef,ab,de') from dual
0
Thank you for reading! This is the end of this article on "sample Analysis of Hive UDF". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.