按照不同部門作為分區(qū),導(dǎo)數(shù)據(jù)到目標(biāo)表
目前創(chuàng)新互聯(lián)建站已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、右江網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
1.創(chuàng)建靜態(tài)分區(qū)表:
create table emp_static_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double)
PARTITIONED BY(deptno int)
row format delimited fields terminated by '\t';
2.插入數(shù)據(jù):
hive>insert into table emp_static_partition partition(deptno=10)
select empno , ename , job , mgr , hiredate , sal , comm from emp where deptno=10;
3.查詢數(shù)據(jù):
hive>select * from emp_static_partition;
1.創(chuàng)建動態(tài)分區(qū)表:
create table emp_dynamic_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double)
PARTITIONED BY(deptno int)row format delimited fields terminated by '\t';
【注意】動態(tài)分區(qū)表與靜態(tài)分區(qū)表的創(chuàng)建,在語法上是沒有任何區(qū)別的
2.插入數(shù)據(jù):
hive>insert into table emp_dynamic_partition partition(deptno)
select empno , ename , job , mgr , hiredate , sal , comm, deptno from emp;
【注意】分區(qū)的字段名稱,寫在最后,有幾個就寫幾個 與靜態(tài)分區(qū)相比,不需要where
需要設(shè)置屬性的值:
hive>set hive.exec.dynamic.partition.mode=nonstrict;
假如不設(shè)置,報錯如下:
3.查詢數(shù)據(jù):
hive>select * from emp_dynamic_partition;
分區(qū)列為deptno,實現(xiàn)了動態(tài)分區(qū)
在生產(chǎn)上我們更傾向是選擇動態(tài)分區(qū),
無需手工指定數(shù)據(jù)導(dǎo)入的具體分區(qū),
而是由select的字段(字段寫在最后,有幾個寫幾個)自行決定導(dǎo)出到哪一個分區(qū)中, 并自動創(chuàng)建相應(yīng)的分區(qū),使用上更加方便快捷 ,在生產(chǎn)工作中用的非常多多。
本文標(biāo)題:生產(chǎn)中Hive靜態(tài)和動態(tài)分區(qū)表,該怎樣抉擇呢?
本文網(wǎng)址:http://chinadenli.net/article22/gpiicc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、商城網(wǎng)站、網(wǎng)站設(shè)計公司、網(wǎng)站導(dǎo)航、Google、網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)