我有一份使用多个映射器和一个减速器的工作。映射器几乎相同,除了 a 的值不同之外String
他们用来产生结果。
目前我有几个类,每个类对应一个值String
我提到过——感觉应该有更好的方法,不需要那么多的代码重复。有没有办法通过这些String
值作为映射器的参数?
我的工作是这样的:
Input File A ----> Mapper A using
String "Foo" ----+
|---> Reducer
Mapper B using ----+
Input File B ----> String "Bar"
我想把它变成这样的:
Input File A ----> GenericMapper parameterized
with String "Foo" ----+
|---> Reducer
GenericMapper parameterized ----+
Input File B ----> with String "Bar"
Edit:这是我目前拥有的两个简化的映射器类。它们准确地反映了我的实际情况。
class MapperA extends Mapper<Text, Text, Text, Text> {
public void map(Text key, Text value, Context context) {
context.write(key, new Text(value.toString() + "Foo"));
}
}
class MapperB extends Mapper<Text, Text, Text, Text> {
public void map(Text key, Text value, Context context) {
context.write(key, new Text(value.toString() + "Bar"));
}
}
Edit:每个映射器应使用什么字符串仅取决于数据来自哪个文件。除了通过文件名之外,无法区分这些文件。