好程序員大數(shù)據(jù)學(xué)習(xí)路線hive內(nèi)部函數(shù)

好程序員大數(shù)據(jù)學(xué)習(xí)路線hive內(nèi)部函數(shù),持續(xù)為大家更新了大數(shù)據(jù)學(xué)習(xí)路線,希望對正在學(xué)習(xí)大數(shù)據(jù)的小伙伴有所幫助。
1、取隨機(jī)數(shù)函數(shù):rand()
語法: rand(),rand(int seed) 返回值: double 說明: 返回一個0到1范圍內(nèi)的隨機(jī)數(shù)。如果指定seed,則會得到一個穩(wěn)定的隨機(jī)數(shù)序列
select rand();
select rand(10);
2、分割字符串函數(shù):split(str,splitor)
語法: split(string str, string pat) 返回值: array 說明: 按照pat字符串分割str,會返回分割后的字符串?dāng)?shù)組,注意特殊分割符的轉(zhuǎn)義
select split(5.0,".")[0];
select split(rand(10)100,".")[0];
3、字符串截取函數(shù):substr,substring
語法: substr(string A, int start),substring(string A, int start) 返回值: string 說明:返回字符串A從start位置到結(jié)尾的字符串
語法: substr(string A, int start, int len),substring(string A, int start, int len) 返回值: string 說明:返回字符串A從start位置開始,長度為len的字符串
select substr(rand()
100,0,2);
select substring(rand()100,0,2);
4、If函數(shù):if
語法: if(boolean testCondition, T valueTrue, T valueFalseOrNull) 返回值: T 說明: 當(dāng)條件testCondition為TRUE時(shí),返回valueTrue;否則返回valueFalseOrNull
select if(100>10,"this is true","this is false");
select if(2=1,"男","女");
select if(1=1,"男",(if(1=2,"女","不知道")));
select if(3=1,"男",(if(3=2,"女","不知道")));
5、條件判斷函數(shù):CASE
第一種格式:
語法: CASE WHEN a THEN b [WHEN c THEN d]
[ELSE e] END 返回值: T 說明:如果a為TRUE,則返回b;如果c為TRUE,則返回d;否則返回e
第二種格式:
語法: CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END 返回值: T 說明:如果a等于b,那么返回c;如果a等于d,那么返回e;否則返回f
select
case 6
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
;
##創(chuàng)建表
create table if not exists cw(
flag int
)
;
load data local inpath '/home/flag' into table cw;
##第一種格式
select
case c.flag
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
from cw c
;
##第二種格式
select
case
when 1=c.flag then "100"
when 2=c.flag then "200"
when 3=c.flag then "300"
when 4=c.flag then "400"
else "others"
end
from cw c
;
6、正則表達(dá)式替換函數(shù):regexp_replace
語法: regexpreplace(string A, string B, string C) 返回值: string 說明:將字符串A中的符合java正則表達(dá)式B的部分替換為C。注意,在有些情況下要使用轉(zhuǎn)義字符,類似oracle中的regexpreplace函數(shù)
select regexp_replace("1.jsp",".jsp",".html");
7、類型轉(zhuǎn)換函數(shù): cast
語法: cast(expr as ) 返回值: Expected "=" to follow "type" 說明: 返回轉(zhuǎn)換后的數(shù)據(jù)類型
select 1;
select cast(1 as double);
select cast("12" as int);
8、字符串連接函數(shù):concat;帶分隔符字符串連接函數(shù):concat_ws
語法: concat(string A, string B…) 返回值: string 說明:返回輸入字符串連接后的結(jié)果,支持任意個輸入字符串
語法: concat_ws(string SEP, string A, string B…) 返回值: string 說明:返回輸入字符串連接后的結(jié)果,SEP表示各個字符串間的分隔符
select "千峰" + 1603 + "班級";
select concat("千峰",1603,"班級");
select concat_ws("|","千峰","1603","班級");
9、排名函數(shù):
rownumber(): 名次不并列 rank():名次并列,但空位 denserank():名次并列,但不空位
##數(shù)據(jù)
id class score
1 1 90
2 1 85
3 1 87
4 1 60
5 2 82
6 2 70
7 2 67
8 2 88
9 2 93

十余年的安遠(yuǎn)網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整安遠(yuǎn)建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“安遠(yuǎn)網(wǎng)站設(shè)計(jì)”,“安遠(yuǎn)網(wǎng)站推廣”以來,每個客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

1 1 90 1
3 1 87 2
2 1 85 3
9 2 93 1
8 2 88 2
5 2 82 3

create table if not exists uscore(
uid int,
classid int,
score double
)
row format delimited fields terminated by '\t'
;
load data local inpath '/home/uscore' into table uscore;
select
u.uid,
u.classid,
u.score
from uscore u
group by u.classid,u.uid,u.score
limit 3
;
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
;
取前三名
select
t.uid,
t.classid,
t.score
from
(
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
) t
where t.rn < 4
;
查看三個排名區(qū)別
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn,
rank() over(distribute by u.classid sort by u.score desc) rank,
dense_rank() over(distribute by u.classid sort by u.score desc) dr
from uscore u
;
10.聚合函數(shù):
min() max() count() count(distinct ) sum() avg()
count(1):不管正行有沒有值,只要出現(xiàn)就累計(jì)1 count(*):正行值只要有一個不為空就給類計(jì)1 count(col):col列有值就累計(jì)1 count(distinct col):col列有值并且不相同才累計(jì)1
11.null值操作
幾乎任何數(shù)和 NULL操作都返回NULL
select 1+null;
select 1/0;
select null%2;
12.等值操作
select null=null; #null
select null<=>null;#true

當(dāng)前文章:好程序員大數(shù)據(jù)學(xué)習(xí)路線hive內(nèi)部函數(shù)
當(dāng)前網(wǎng)址:http://muchs.cn/article30/jcjhso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、企業(yè)建站、面包屑導(dǎo)航、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄外貿(mào)網(wǎng)站建設(shè)

廣告

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

成都網(wǎng)站建設(shè)公司