0

我的映射器实现

public class SimpleMapper extends Mapper<Text, Text, Text, MapWritable> {

@Override
protected void map(Text key, Text value,Context context)
        throws IOException, InterruptedException {

            MapWritable writable = new LinkedMapWritable();
            writable.put("unique_key","one");
            writable.put("another_key","two");
            context.write(new Text("key"),writable );
        }

}

Reducer 的实现是:

public class SimpleReducer extends Reducer<Text, MapWritable, NullWritable, Text> {
@Override
protected void reduce(Text key, Iterable<MapWritable> values,Context context)
        throws IOException, InterruptedException {

            // The map writables have to be ordered based on the "unique_key" inserted into it
        }

}

我必须使用二级排序吗?还有其他方法吗?

4

1 回答 1

1

reducer 中的 MapWritable(值)总是以不可预知的顺序排列,此顺序可能因运行而异,您无法控制它。

但是 Map/Reduce 范式保证提供给 reducer 的键将按排序顺序排列,并且属于单个键的所有值都将转到单个 reducer。

因此,您绝对可以为您的用例使用辅助排序和自定义分区器。

于 2014-06-20T03:30:38.067 回答