感謝:html
http://bbs.elecfans.com/jishu_1600211_1_1.htmlnode
https://www.deeplearn.me/1536.html服務器
動態分區:app
在對分區表插入數據時,不指定(或不所有指定)分區字段的值,數據會插入到哪一個分區由數據自身值決定。ui
靜態分區:spa
在對分區表插入數據的時候,經過手動指定所有分區字段的值來把數據插入到肯定分區。code
hive.exec.dynamic.partition=true :是否容許動態分區orm
hive.exec.dynamic.partition.mode=strict :分區模式設置htm
strict:最少須要有一個是靜態分區blog
nostrict:能夠所有是動態分區
hive.exec.max.dynamic.partitions=1000 :容許動態分區的最大數量
hive.exec.max.dynamic.partitions.pernode =100 :單個節點上的mapper/reducer容許建立的最大分區
##建立臨時表
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;
分區注意細節
(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語句。
全部事務自動提交
指支持orc格式
使用bucket表
配置hive參數,使其支持事務
靜態分區和動態分區