1
|
package eu.dnetlib.iis.core.examples.javamapreduce;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import org.apache.avro.mapred.AvroKey;
|
6
|
import org.apache.avro.mapred.AvroValue;
|
7
|
import org.apache.hadoop.io.NullWritable;
|
8
|
import org.apache.hadoop.mapreduce.Reducer;
|
9
|
|
10
|
import eu.dnetlib.iis.core.examples.schemas.documentandauthor.Person;
|
11
|
|
12
|
/**
|
13
|
* @author Mateusz Kobos
|
14
|
*/
|
15
|
public class PersonClonerReducer
|
16
|
extends Reducer<AvroKey<String>, AvroValue<Person>, AvroKey<Person>, NullWritable> {
|
17
|
|
18
|
/**
|
19
|
* Copy the data without introducing any changes
|
20
|
*/
|
21
|
@Override
|
22
|
public void reduce(AvroKey<String> key,
|
23
|
Iterable<AvroValue<Person>> values, Context context)
|
24
|
throws IOException, InterruptedException {
|
25
|
CharSequence name = key.datum();
|
26
|
for(AvroValue<Person> value : values) {
|
27
|
if(!name.equals(value.datum().getName())){
|
28
|
throw new RuntimeException(
|
29
|
"Person objects processed by the reducer do not have the same name! "+
|
30
|
"I.e., "+name+" != "+value.datum().getName()+". "+
|
31
|
"This is not possible, since the name should be the key of the reducer");
|
32
|
}
|
33
|
context.write(new AvroKey<Person>(value.datum()),
|
34
|
NullWritable.get());
|
35
|
}
|
36
|
}
|
37
|
}
|