大數據學習之提交job流程,分區和合並11
阿新 • • 發佈:2019-05-04
hadoop port class mapper 平均值 ria spa 流程 bst 3:代碼改寫:使用上回的WordCount程序。添加如下代碼就行了
一:合並(mapTask的合並)
使用合並的註意事項:
(1)合並是一種特殊的Reducer
(2)合並是在Mapper端執行一次合並,用於減少Mapper輸出到Reducer的數據量,可以提高效率。
(3)舉例:以WordCount為例
(4)註意:一定要謹慎使用Combiner,有些不能使用:求平均值
有Combiner,或者沒有Combiner,都不能改變Map和Reduce對應數據的類型
原理圖:
1:maptask並行度與決定機制
2 maptask工作機制
3:代碼改寫:使用上回的WordCount程序。添加如下代碼就行了
二:自定義分區
1:自定義一個Partition類(直接使用上次那個流量統計那個代碼)
package it.dawn.YARNPra.flow流量匯總序列化.partition; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Partitioner; /** * @author Dawn * @date 2019年5月3日22:03:08 * @version 1.0 * 自定義一個分區 */ public class PhonenumPartitioner extends Partitioner<Text, FlowBean>{ //根據手機號前三位進行分區 @Override public int getPartition(Text key, FlowBean value, int numpartitions) { //1.獲取手機號前三位 String phoneNum=key.toString().substring(0, 3); //2:分區 int partitioner=4; if("135".equals(phoneNum)) { return 0; }else if("137".equals(phoneNum)){ return 1; }else if("138".equals(phoneNum)) { return 2; }else if("139".equals(phoneNum)) { return 3; } return partitioner; } }
2:在Driver類中添加Partiton的分區個數
3:運行結果
大數據學習之提交job流程,分區和合並11