小編給大家分享一下hive如何創(chuàng)建分區(qū),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)主營會(huì)同網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,會(huì)同h5成都小程序開發(fā)搭建,會(huì)同網(wǎng)站營銷推廣歡迎會(huì)同等地區(qū)企業(yè)咨詢
HIVE的分區(qū)通過在創(chuàng)建表時(shí)啟用partitionby實(shí)現(xiàn),用來partition的維度并不是實(shí)際數(shù)據(jù)的某一列,具體分區(qū)的標(biāo)志是由插入內(nèi)容時(shí)給定的。當(dāng)要查詢某一分區(qū)的內(nèi)容時(shí)可以采用where語句,形似where tablename.partition_key >a來實(shí)現(xiàn)。
創(chuàng)建含分區(qū)的表。
命令原型:
CREATE TABLE page_view(viewTime INT, userid BIGINT,
page_urlSTRING, referrer_url STRING,
ip STRINGCOMMENT 'IP Address of the User')
COMMENT 'This isthe page view table'
PARTITIONED BY(dtSTRING, country STRING)
CLUSTEREDBY(userid) SORTED BY(viewTime) INTO 32 BUCKETS
ROW FORMATDELIMITED
FIELDSTERMINATED BY '\001'
COLLECTION ITEMSTERMINATED BY '\002'
MAP KEYSTERMINATED BY '\003'
STORED ASSEQUENCEFILE;
Eg:
建表:
CREATE TABLE c02_clickstat_fatdt1
(yyyymmdd string,
id INT,
ip string,
country string,
cookie_id string,
page_id string ,
clickstat_url_id int,
query_string string,
refer string
)PARTITIONED BY(dt STRING)
row format delimited fields terminated by '\005' stored astextfile;
裝載數(shù)據(jù):
LOAD DATA INPATH'/user/admin/SqlldrDat/CnClickstat/20101101/19/clickstat_gp_fatdt0/0' OVERWRITEINTO TABLE c02_clickstat_fatdt1
PARTITION(dt='20101101');
訪問某一個(gè)分區(qū)
SELECT count(*)
FROMc02_clickstat_fatdt1 a
WHERE a.dt >='20101101' AND a.dt < '20101102';
以上是“hive如何創(chuàng)建分區(qū)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!