美文网首页
hive字符串函数

hive字符串函数

作者: 尤小闹 | 来源:发表于2018-06-07 11:53 被阅读0次

    1.regexp_replace 正则表达式替换函数

    语法: regexp_replace(string A, string B, string C)

    返回值: string

    说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符

    hive> select regexp_replace(‘foobar’, ‘oo|ar’, ”) from dual;
    fb
    

    2.regexp_extract 正则表达式解析函数

    语法: regexp_extract(string subject, string pattern, int index)

    返回值: string

    说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。注意,在有些情况下要使用转义字符

    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
    

    3.parse_url URL解析函数

    语法: parse_url(string urlString, stringpartToExtract [, string keyToExtract])

    返回值: string

    说明:返回URL中指定的部分。partToExtract的有效值为:HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO.

    hive> select parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1′, ‘HOST’) from dual;
    facebook.com
    hive> select parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1′, ‘QUERY’, ‘k1′) from dual;
    v1
    

    4.get_json_object json解析函数

    语法: get_json_object(string json_string, string path)

    返回值: string

    说明:解析json的字符串json_string,返回path指定的内容。如果输入的json字符串无效,那么返回NULL。

    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
    

    相关文章

      网友评论

          本文标题:hive字符串函数

          本文链接:https://www.haomeiwen.com/subject/tqxgsftx.html