You can make a replacement with this code:
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
But it is not MapSide join. To do MapSide join you should read file with replacements (InputFile 1
) in every mapper (in setup phase) and then join this data with InputFile 2
in map phase. Example:
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
}