Hadoop MapSide加入乔布斯先生

Hadoop MapSide加入乔布斯先生,hadoop,mapreduce,Hadoop,Mapreduce,我使用mapsidejoin在我的MR作业中获取两个不同的文件 Input File 1: 0,5.3 26,4.9 54,4.9 . . . InputFile 2: 0 Anju,,3.6,IT,A,1.6,0.3 26 Remya,,3.3,EEE,B,1.6,0.3 54 akhila,,3.3,IT,C,1.3,0.3 我的意图是替换如下内容 Anju,5.3,3.6,IT,A,1.6,0.3 Remya,4.9,3.3,EEE,B,1.6,0.3 akhila,4.9,3

我使用mapsidejoin在我的MR作业中获取两个不同的文件

Input File 1:
0,5.3
26,4.9
54,4.9
.
.
.

InputFile 2:
0   Anju,,3.6,IT,A,1.6,0.3
26  Remya,,3.3,EEE,B,1.6,0.3
54  akhila,,3.3,IT,C,1.3,0.3
我的意图是替换如下内容

Anju,5.3,3.6,IT,A,1.6,0.3
Remya,4.9,3.3,EEE,B,1.6,0.3
akhila,4.9,3.3,IT,C,1.3,0.3
我所做的是

为了得到2个文件作为输入,我使用了2个MapperMultipleInput

两个文件的第一列是文件偏移量

在第1个映射中,我将第一个列作为keyLogwritable偏移量发出,其余列作为第1个文件的值发出 在第2个映射中,我还将第一个列作为keyLogwritable偏移量发出,其余列作为第2个文件的值发出

所以在减速机里我可以

Reducer
key 0
value 5.3
value Anju,S,3.6,IT,A,1.6,0.3

Reducer
key 26
value Remya,,3.3,EEE,B,1.6,0.3
value 4.9

Reducer
key 54
value 4.9
value akhila,,3.3,IT,C,1.3,0.3
我将如何替换任何想法

我的方法是否正确,或者我是否应该采用其他方法?
请建议。

您可以使用以下代码进行替换:

String result = null;
String replacement = null;
for (Text value: values) {
    String valueStr = value.toString();
    if (valueStr.contains(",,")) {
        result = valueStr;
    } else {
        replacement = valueStr;
    }
}
if (result == null || replacement == null) {
    return;
}
result = result.replaceFirst(",,", "," + replacement + ",");
// write result
但这不是MapSide连接。要进行MapSide连接,您应该在安装阶段的每个映射程序中读取带有替换的InputFile 1的文件,然后在映射阶段将此数据与InputFile 2连接。例如:

private Map < Integer, Double > replacements;

@Override
protected void setup(Context context) throws IOException, InterruptedException {
    replacements = new HashMap < Integer, Double > ();
    // read FileInput 1 to replacements
    // ...
}

@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String[] parts = value.toString().split("\t"); // 0   Anju,,3.6,IT,A,1.6,0.3
    Integer id = Integer.parseInt(parts[0]);
    if (!replacements.containsKey(id)) {
        return; // can't replace
    }
    Double replacement = replacements.get(id);
    String result = parts[1].replaceFirst(",,", "," + replacement + ",");
    // write result to context
}

是的,这是对的。但是我的2个文件的容量很大。在替换中保存这些值可能会导致大量内存使用,并可能导致heapspace