本篇內容介紹了“Hive的靜態分區與動態分區的區別”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
1.
靜態分區:若分區的值是確定的,那么稱為靜態分區。新增分區或者是加載分區數據時,已經指定分區名。
create table if not exists day_part1(
uid int,
uname string
)
partitioned by(year int,month int)
row format delimited fields terminated by '\t';
##加載數據指定分區
load data local inpath '/root/Desktop/student.txt' into table day_part1
partition(year=2017,month=04);
##新增分區指定分區名
alter table day_part1 add partition(year=2017,month=1)
partition(year=2016,month=12);
2. 動態分區:分區的值是非確定的,由輸入數據來確定
2.1 動態分區的相關屬性:
hive.exec.dynamic.partition=true :是否允許動態分區
hive.exec.dynamic.partition.mode=strict :分區模式設置
strict:最少需要有一個是靜態分區
nostrict:可以全部是動態分區
hive.exec.max.dynamic.partitions=1000 :允許動態分區的最大數量
hive.exec.max.dynamic.partitions.pernode =100
:單個節點上的mapper/reducer允許創建的最大分區
2.2 動態分區的操作
##創建臨時表
create table if not exists tmp
(uid int,
commentid bigint,
recommentid bigint,
year int,
month int,
day int)
row format delimited fields terminated by '\t';
##加載數據
load data local inpath '/root/Desktop/comm' into table tmp;
##創建動態分區表
create table if not exists dyp1
(uid int,
commentid bigint,
recommentid bigint)
partitioned by(year int,month int,day int)
row format delimited fields terminated by '\t';
##嚴格模式
insert into table dyp1 partition(year=2016,month,day)
select uid,commentid,recommentid,month,day from tmp;
##非嚴格模式
##設置非嚴格模式動態分區
set hive.exec.dynamic.partition.mode=nostrict;
##創建動態分區表
create table if not exists dyp2
(uid int,
commentid bigint,
recommentid bigint)
partitioned by(year int,month int,day int)
row format delimited fields terminated by '\t';
##為非嚴格模式動態分區加載數據
insert into table dyp2 partition(year,month,day)
select uid,commentid,recommentid,year,month,day from tmp;
3.分區注意細節
(1)、盡量不要用動態分區,因為動態分區的時候,將會為每一個分區分配reducer數量,當分區數量多的時候,reducer數量將會增加,對服務器是一種災難。
(2)、動態分區和靜態分區的區別,靜態分區不管有沒有數據都將會創建該分區,動態分區是有結果集將創建,否則不創建。
(3)、hive動態分區的嚴格模式和hive提供的hive.mapred.mode的嚴格模式。
hive提供我們一個嚴格模式:為了阻止用戶不小心提交惡意hql
hive.mapred.mode=nostrict : strict
如果該模式值為strict,將會阻止以下三種查詢:
(1)、對分區表查詢,where中過濾字段不是分區字段。
(2)、笛卡爾積join查詢,join查詢語句,不帶on條件或者where條件。
(3)、對order by查詢,有order by的查詢不帶limit語句。
“Hive的靜態分區與動態分區的區別”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。