控制Map數(shù)的個數(shù)
讀取小文件較多,那么則需要在map端進(jìn)行小文件合并,參數(shù)設(shè)置如下:
-- 設(shè)置輸入文件格式
set hive.input.format?=?org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
--是否支持可切分的CombieInputFormat ,true是支持
set hive.hadoop.supports.splittable.combineinputformat?= true;
set mapreduce.input.fileinputformat.split.maxsize?= 256000000;
set mapreduce.input.fileinputformat.split.minsize.per.node=256000000;
set mapreduce.input.fileinputformat.split.minsize.per.rack=256000000;
控制Reduce數(shù)目
在設(shè)置動態(tài)分區(qū)后,產(chǎn)生的文件數(shù)會取決于map數(shù)和分區(qū)數(shù)的大小,假設(shè)動態(tài)分區(qū)初始有N個map數(shù),同時生成M個分區(qū),則中間會生成N*M個文件,通常這種情況就是讓大部分?jǐn)?shù)據(jù)盡量輸出到一個reduce中進(jìn)行處理,但是有些HiveSql不會產(chǎn)生reduce,也就是說文件最后沒有進(jìn)行合并處理,這種情況下可以用distribute by rand()的方式保證數(shù)據(jù)進(jìn)行一次reduce操作,實現(xiàn)文件的合并。
兩種處理方式參數(shù)設(shè)置如下:
a. 設(shè)置reduce個數(shù)
set mapred.reduce.tasks=50;
insert into table xxx
select? * from ?xxx distribute by rand();
備注:set設(shè)置的參數(shù)是生成的文件個數(shù),distribute by rand()保證數(shù)據(jù)隨機(jī)分配到50個文件中。?
b. 設(shè)置每個reducer處理的數(shù)據(jù)
set hive.exec.reducers.bytes.per.reducer=5120000000;
insert into table xxx
select? *? from? ?xxx?? distribute by rand();
備注:set設(shè)置的參數(shù)是生成的文件大小,distribute by rand()保證數(shù)據(jù)的平均大小是512Mb。