2013-08-18 11 views
1

你好我地圖找位問題,降低chaining.i必須從我的第一個映射器,形成這樣地圖降低鏈接無法正常執行

mapper-> reducer->映射

鏈減速器流一直不錯,這減速機的輸出數據是不會下一個映射properly.this是一個簡單的代碼示例我曾嘗試

這是我的第一映射

public void map(LongWritable key, Text value, 
     OutputCollector<Text, IntWritable> outputCollector, Reporter reporter) 
     throws IOException { 

    String maxSalary = value.toString().split(",")[4]; 

    outputCollector.collect(new Text("max salary"),new IntWritable(Integer.parseInt(maxSalary))); 

} 

這是我減速

public void reduce(Text key, Iterator<IntWritable> values, 
      OutputCollector<Text, IntWritable> outputCollector, Reporter reporter) 
      throws IOException { 
     int maxSalary = Integer.MIN_VALUE; 

     while(values.hasNext()){ 

      maxSalary = Math.max(maxSalary, values.next().get()); 
     } 
     outputCollector.collect(key, new IntWritable(maxSalary)); 

    } 

這是我的下一個簡單的映射

public void map(Text key, IntWritable value, 
      OutputCollector<Text, IntWritable> outputCollector, Reporter reporter) 
      throws IOException { 

     System.out.println(value.toString()); 
    } 

這是運行作業

JobConf jobConf = new JobConf(jobrunner.class); 
jobConf.setJobName("Chaining"); 

FileInputFormat.setInputPaths(jobConf, new Path("hdfs://localhost:9000/employee_data.txt")); 
FileOutputFormat.setOutputPath(jobConf,new Path("hdfs://localhost:9000/chain9.txt")); 

JobConf conf1 = new JobConf(false); 

ChainMapper.addMapper(jobConf,chainmap.class,LongWritable.class,Text.class,Text.class,IntWritable.class,true,conf1); 

JobConf conf2 = new JobConf(false); 

ChainReducer.setReducer(jobConf, chainreduce.class,Text.class,IntWritable.class,Text.class,IntWritable.class,true,conf2); 

JobConf conf3 = new JobConf(false); 

ChainMapper.addMapper(jobConf, nextchainmap.class, Text.class,IntWritable.class,Text.class,IntWritable.class,true,conf3); 


JobClient.runJob(jobConf); 
我的主類

我將獲得最高員工工資我的reducer和這個必須傳遞給下一個映射器,在那裏它可以找到最大薪水值的員工記錄,我如何在ne xt mapper?任何想法?

回答

2

要鏈接第二個映射器,您需要調用ChainReducer.addMapper(...)而不是ChainMapper.addMapper(...)

+0

謝謝,現在在下一個映射器我得到了所需的值,現在在下一個映射器中,我必須再次處理文件的記錄,基於reducer的值,即我從reducer的最大薪水值,並基於此價值我應該得到最高工資的僱員的記錄..任何幫助嗎? – user1585111

+0

您應該針對另一個問題詢問其他問題。在此期間,如果它解決了你的第一個問題,請接受我的答案:) –