hadoop - 如何维护 Reducer 中 MapWritables 的顺序?

标签 hadoop mapreduce writable

我的映射器实现

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
        }

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

最佳答案

reducer 中的 MapWritable (values) 始终处于不可预测的顺序,此顺序可能会因运行而异,您无法控制它。

但是 Map/Reduce 范式保证的是呈现给 reducer 的键将按排序顺序排列,属于单个键的所有值将进入单个 reducer。

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

关于hadoop - 如何维护 Reducer 中 MapWritables 的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24316641/

相关文章:

mysql - 加载到 Hive 表时转换为 parquet 文件格式

hadoop - Hive:创建表和分区依据

c# - 找出一组属性之间最相似的(mongodb)

javascript - Javascript 可写描述符是否会阻止实例发生更改?

serialization - Hadoop中的序列化-可写

apache-spark - 如果不使用Map Reduce,Hive 3上的Hive ORC ACID是否需要TEZ?

apache-spark - 避免在Spark Streaming中为空分区写入文件

scala - 学习mapreduce,SQL命令如何翻译成mapreduce数据流。字数统计示例不能满足我的理解。

python - 有类似 DatastoreOutputWriter 的东西吗?

nested - 预期实例,获得 OrderedDict Django Rest Framework 可写嵌套序列化器