0

我有一个 Java MR 程序。我的 Map 方法的输出是各种字符串/数字,我现在将它们放入字符串中。然后在 Reduce 中拆分字符串并使用参数。现在我想知道这是否更容易完成。

我正在考虑一个地图,我将我的字符串/数字存储为值,并带有一个描述每个值的命名键。这个地图将是我的“价值输出”(MapOutputValueClass)。

这可能吗?当我在文档中读到这个时,我想我的想法是不可实现的:

The key and value classes have to be serializable by the framework and hence need to implement the Writable interface. Additionally, the key classes have to implement the WritableComparable interface to facilitate sorting by the framework.

那么你会建议我为我的 MapOutputValueClass 选择什么?:-) 也许拿一张地图并将其转换为 ImmutableBytesWritable?我也不想放慢我的程序...

感谢您的回答!

4

1 回答 1

1

您可以使用各种字符串/数字编写自己的类。例如,将其作为 mapper 的输出值类和 reducer 的输入值类传递。

Class Foo{
     String A;
     String B;
     int c, d;

      ....
}

在您的映射器中:

public class MyMapper extends Mapper<Text, Text, Text, Foo>{
      ....
}

在你的减速机中:

public class MyReducer extends Reducer<Text, Foo, Text, LongWritable>{
       ...
}

在您的驱动程序中:

设置映射器输出值类:

job.setMapOutputValueClass(Foo.class);

记住当你extends Mapper,你需要填写的类是这样的顺序:<KEYIN_CLASS, VALUEIN_CLASS, KEYOUT_CLASS, VALUEOUT_CLASS>,同样的事情Reducer

于 2012-06-19T19:22:21.407 回答