복붙노트

[HADOOP] 정확히 매퍼 및 감속기 기능의 출력은 무엇입니까

HADOOP

정확히 매퍼 및 감속기 기능의 출력은 무엇입니까

이 맵리 듀스와 하둡을 사용하여 특정 값을 포함하는 행을 추출의 후속 질문 매퍼 기능

public static class MapForWordCount extends Mapper<Object, Text, Text, IntWritable>{

private IntWritable saleValue = new IntWritable();
private Text rangeValue = new Text();

public void map(Object key, Text value, Context con) throws IOException, InterruptedException
{
    String line = value.toString();
    String[] words = line.split(",");
    for(String word: words )
    {
        if(words[3].equals("40")){  
            saleValue.set(Integer.parseInt(words[0]));
            rangeValue.set(words[3]);
            con.write( rangeValue , saleValue );
        }
    }
}   
}

감속기 기능

public static class ReduceForWordCount extends Reducer<Text, IntWritable, Text, IntWritable>  
{  
    private IntWritable result = new IntWritable();  
    public void reduce(Text word, Iterable<IntWritable> values, Context con) throws IOException, InterruptedException  
    {  
        for(IntWritable value : values)  
        {  
            result.set(value.get());  
            con.write(word, result);  
        }  
    }  
}

출력 수득

40 105  
40 105  
40 105  
40 105

편집 1 : 그러나 예상 출력은

40 102  
40 104  
40 105

내가 무엇을 잘못하고 있지 ?

무엇 정확히 매퍼 및 감속기 기능이 여기에 무슨 일이 일어나고?

해결법

  1. ==============================

    1.원래의 질문의 맥락에서 - 당신은 회원님이 중복 항목이 그대로 매퍼에 나 감속기에 루프가 필요하지 않습니다 :

    원래의 질문의 맥락에서 - 당신은 회원님이 중복 항목이 그대로 매퍼에 나 감속기에 루프가 필요하지 않습니다 :

    public static class MapForWordCount extends Mapper<Object, Text, Text, IntWritable>{
    
    private IntWritable saleValue = new IntWritable();
    private Text rangeValue = new Text();
    
    public void map(Object key, Text value, Context con) throws IOException, InterruptedException
    {
        String line = value.toString();
        String[] words = line.split(",");
        if(words[3].equals("40")){  
           saleValue.set(Integer.parseInt(words[0]));
           rangeValue.set(words[3]);
           con.write(rangeValue , saleValue );
        }
    }   
    }
    

    원래의 질문에 @Serhiy에 의해 제안 그리고 감속기, 당신은 단 한 줄의 코드 만 필요합니다 :

    public static class ReduceForWordCount extends Reducer<Text, IntWritable, Text, IntWritable>  
    {  
    private IntWritable result = new IntWritable();  
    public void reduce(Text word, Iterable<IntWritable> values, Context con) throws IOException, InterruptedException  
    {  
        con.write(word, null);  
    } 
    

    "수정 1"Regrading 것은 - 나는 그것을 사소한 연습을 떠날 것입니다 :)

  2. ==============================

    2.당신은 쉼표를 분할, 쉼표로 구분 된 텍스트의 라인을 소모하고, 일부 값을 필터링하고 있습니다. 모든 경우에만 해당 값을 추출한다하고 있다면 con.write ()는 한 번에 한 줄 호출해야합니다.

    당신은 쉼표를 분할, 쉼표로 구분 된 텍스트의 라인을 소모하고, 일부 값을 필터링하고 있습니다. 모든 경우에만 해당 값을 추출한다하고 있다면 con.write ()는 한 번에 한 줄 호출해야합니다.

    당신 출력과 해당 키에 기록 된 모든 값의 목록을 형성하는 매퍼는 것이다 그룹 모두 "40"키. 그리고 그 만회 이상 읽고 것입니다.

    당신은 아마지도 기능에 대해이 작업을 시도해야합니다.

    // Set the values to write 
    saleValue.set(Integer.parseInt(words[0]));
    rangeValue.set(words[3]);
    
    // Filter out only the 40s
    if(words[3].equals("40")) {
        // Write out "(40, safeValue)" words.length times 
        for(String word: words )
        {
            con.write( rangeValue , saleValue );
        }
    }
    

    당신이 분할 문자열의 길이에 대한 중복 값을 원하지 않는 경우, 다음 for 루프 제거하기.

    모든 감속기 그냥 매퍼로부터받은 무엇을 인쇄하고하고있다.

  3. ==============================

    3.매퍼 출력은 다음과 같이 될 것이다 :

    매퍼 출력은 다음과 같이 될 것이다 :

    <word,count>
    

    감속기 출력은 다음과 같이 될 것이다 :

    <unique word, its total count>
    

    예 : 광고를 판독하고있는 모든 단어가 <키 값> 쌍에 넣어 계산된다 :

    <40,1>
    <140,1>
    <50,1>
    <40,1> ..
    

    여기 40,50,140 .. 모든 키가 있고 값은 줄에 해당 키의 발생 수의 수입니다. 이것은 매퍼에 발생합니다.

    그리고,이 키는 valuepairs 유사 키가 모두 하나의 키로 감소하고 해당 키의 모든 값 동료는 키 - 값 쌍의 값을 제공하는 합산되는 감속기로 전송된다. 그래서, 감속기의 결과는 다음과 같을 것이다 :

    <40,10>
    <50,5>
    ...
    

    귀하의 경우, 감속기는 아무것도하지 않습니다. 맵퍼 구해진 고유 값 / 단어 만 출력 교체 주어진다.

    이상적으로, 당신은 절감 및 같은 출력을 얻을로되어있다 : "40150"이 같은 줄에 5 번 발견되었다.

  4. from https://stackoverflow.com/questions/37093158/what-exactly-is-output-of-mapper-and-reducer-function by cc-by-sa and MIT license