-1

众所周知,无论是这

public static class SReducer extends MapReduceBase implements Reducer<Text, Text, Text, Text>
     {

        public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException
        {
            StringBuilder sb = new StringBuilder();
            while (key.hasNext()) 
            {
                sb.append(key.next().toString());   
            }
            output.collect(key, new Text(sb.toString()));
        }

     }

或者

public static class Reduce extends MapReduceBase implements Reducer<Text, Text, Text, Text> 
    {
        public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
        {
            boolean start = true;
            StringBuilder sb = new StringBuilder();
            while (values.hasNext()) 
            {
                if(!start)
                {
                start=false;
                sb.append(values.next().toString());
                }           
            }
            output.collect(key, new Text(sb.toString()));
        }
    }

这是我们用来消除输出中重复“值”的一种 reducer 函数。但是我应该怎么做才能消除重复的“钥匙”?任何想法?谢谢。

PS:更多信息:在我的 <key,values> 对中,键包含链接,值包含单词。但是在我的输出中,每个单词只出现一次,但是我得到了很多重复的链接。

4

1 回答 1

3

在 中,对于接收到的每个唯一键,Reducer都会有一次调用。它将接收该键的所有值。但是,如果您只关心键,并且只关心唯一键,那么就完全忽略这些值。每把钥匙你都会得到一个;用那个(非重复的)键做任何你想做的事。reduce()Reducerreduce()

于 2012-04-30T20:42:22.240 回答