hive內(nèi)置函數(shù)怎么用

小編給大家分享一下hive內(nèi)置函數(shù)怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

公司主營業(yè)務(wù):成都網(wǎng)站設(shè)計、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)公司推出本溪免費做網(wǎng)站回饋大家。

cli命令

show functions;

desc function concat;

desc function extended concat;查看某個函數(shù)怎么使用的例子

nvl函數(shù)
coalesce(v1,v2,...)返回參數(shù)中第一個非空值,如果所有值都為null返回null;


set.cli.print.header=true;

winfunc

員工 工資 標識

id  money type

關(guān)系型運算符優(yōu)先級高到低為:not and or
and or 優(yōu)先級

select id ,money from winfunc where id='1001' or id='1002'
     and money ='100'; 
    
結(jié)果

    1001  100
    1001  150
    1001  200
    1001  150
    1002  100

正確的sql應(yīng)該是

select id ,money from winfunc where (id='1001' or id='1002') and money ='100';

結(jié)果

     1001  100
     1002  100


if(con,v1,v2)

    select if(2>1,'v1','v2') from dual;
    v1

case when

select case when id='1001' then 'v1' when id='1002' then 'v2' else 'v3' end from winfunc;

get_json_object

select get_json_object('{"name":"jack","age":"20"}','$.name') from dual;
jack

parse_url

 select parse_url('http://facebook.com/path2/p.php?k1=v1&k2=v2#Ref1', 'HOST') from
    lxw_dual;
    facebook.com

select parse_url('http://facebook.com/path2/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1')
    from lxw_dual;
    v1



concat_ws比concat多了個拼接字符串之間的分隔符

concat_ws(string SEP,array<string>)對數(shù)組里的值處理


collect_set(id)去重返回數(shù)組

    
    select collect_set(id) from winfunc;
    ["1001","1002","1003","1004"]

collect_list(id)不去重返回數(shù)組

    select collect_list(id) from winfunc;



partition by關(guān)鍵字是oracle中分析性函數(shù)的一部分,它和聚合函數(shù)不同的地方在于它能返回一個分組中的多條記錄,而聚合函數(shù)一般只有一條反映統(tǒng)計值的記錄

sum() over (PARTITION BY ...) 是一個分析函數(shù)。 他執(zhí)行的效果跟普通的sum ...group by ...不一樣,它計算組中表達式的累積和,而不是簡單的和。


Group By 和 Having, Where ,Order by這些關(guān)鍵字是按照如下順序進行執(zhí)行的:Where, Group By, Having, Order by。

在這四個關(guān)鍵字中,只有在Order By語句中才可以使用最終視圖的列名,如:
 
SELECT FruitName, ProductPlace, Price, ID AS IDE, Discount
FROM T_TEST_FRUITINFO
WHERE (ProductPlace = N'china')
ORDER BY IDE
這里只有在ORDER BY語句中才可以使用IDE,其他條件語句中如果需要引用列名則只能使用ID,而不能使用IDE。

ORDER BY 子句中的列必須包含在聚合函數(shù)或 GROUP BY 子句中。

GROUP BY 和 ORDER BY一起使用時,ORDER BY要在GROUP BY的后面。




一、窗口函數(shù)

 first_value(求組的第一個值)
    
    select id,money,
    first_value(money) over (partition by id order by money
    rows between 1 preceding and 1 following) 
    from winfunc

每行對應(yīng)的數(shù)據(jù)窗口是從第一行到最后一行
    rows between unbounded preceding and unbounded following

lead(money,2) 取后面距離為2的記錄值,沒有就取null

    select id,money,lead(money,2) over(order by money) from winfunc


lag(money,2)于lead相反


rank()排序函數(shù)與row_number()

select id,money, rank() over (partition by id order by money) from winfunc
結(jié)果

    1001 100 1
    1001 150 2
    1001 150 2
    1001 200 4

dense_rank()

select id,money, dense_rank() over (partition by id order by money) from winfunc

結(jié)果

    1001 100 1
    1001 150 2
    1001 150 2
    1001 200 3

cume_dist()

計算公式:CUME_DIST 小于等于當前值的行數(shù)/分組內(nèi)總行數(shù)–比如,統(tǒng)計小于等于當前薪水的人數(shù),所占總?cè)藬?shù)的比例


    select id,money, cume_dist() over (partition by id order by money) from winfunc

結(jié)果

    1001 100 0.25
    1001 150 0.75
    1001 150 0.75
    1001 200 1

percent_rank(),第一個總是從零開始
PERCENT_RANK() = (RANK() – 1) / (Total Rows – 1)

計算公式:(相同值最小行號-1)/(總行數(shù)-1)

結(jié)果

    1001 100 0
    1001 150 0.33
    1001 150 0.33
    1001 200 1

ntile(2) 分片


asc時, nulls last為默認
desc時, nulls first為默認

select id,money, ntile(2) over (order by money desc nulls last) from winfunc;


混合函數(shù)(使用java里面的方法)

java_method和reflect是一樣的


select java_method("java.lang.Math","sqrt",cast(id as double)) from winfunc;


UDTF表函數(shù)explode()配合lateral view關(guān)鍵字

select id ,adid from winfunc lateral view explode(split(type,'B')) tt as adid


1001 ABC

列轉(zhuǎn)行

1001 A

1001 C


正則表達式函數(shù)

like 字符"_"表示任意單個字符,而字符"%"表示任意數(shù)量的字符

rlike后面跟正則表達式

select 1 from dual where 'footbar' rlike  '^f.*r$';

正則表達式替換函數(shù)

regexp_replace(string A,string B,string C)
將字符串A中符合java正則表達式B的部分替換為C

select regexp_replace('foobar','oo|ar','') from dual;

返回fb


regexp_extract(string subject,string pattern,int index)


select regexp_extract('foothebar','foo(.*?)(bar)',1) from dual;

返回the,()正則表達式中表示組,1表示第一個組的索引


1.貪婪匹配(.*), |一直匹配到最后一個|


    select regexp_extract('979|7.10.80|8684','.*\\|(.*)',1) from dual;

返回8684


2.非貪婪匹配(.*?)加個問號告訴正則引擎,盡可能少的重復(fù)上一個字符


    select regexp_extract('979|7.10.80|8684','(.*?)\\|(.*)',1) from dual;

以上是“hive內(nèi)置函數(shù)怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當前文章:hive內(nèi)置函數(shù)怎么用
標題URL:http://muchs.cn/article28/ijdhcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、電子商務(wù)、定制開發(fā)、服務(wù)器托管網(wǎng)站營銷、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)