1 |
53779
|
claudio.at
|
package eu.dnetlib.data.mapreduce.hbase.dataimport;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.actionmanager.actions.AtomicAction;
|
4 |
|
|
import org.apache.hadoop.io.Text;
|
5 |
|
|
import org.apache.hadoop.mapreduce.Reducer;
|
6 |
|
|
|
7 |
|
|
import java.io.IOException;
|
8 |
|
|
import java.util.Iterator;
|
9 |
|
|
|
10 |
|
|
public class DOIBoostImportReducer extends Reducer<Text, Text, Text, Text> {
|
11 |
|
|
|
12 |
|
|
private Text keyout;
|
13 |
|
|
private Text valueOut;
|
14 |
|
|
|
15 |
|
|
@Override
|
16 |
|
|
protected void setup(Context context) throws IOException, InterruptedException {
|
17 |
|
|
keyout = new Text("");
|
18 |
|
|
valueOut = new Text("");
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
@Override
|
22 |
|
|
protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
|
23 |
|
|
final Iterator<Text> iterator = values.iterator();
|
24 |
|
|
if (iterator.hasNext()) {
|
25 |
|
|
|
26 |
|
|
final String aaString = iterator.next().toString();
|
27 |
|
|
final AtomicAction aa = AtomicAction.fromJSON(aaString);
|
28 |
|
|
|
29 |
|
|
keyout.set(aa.getRowKey());
|
30 |
|
|
valueOut.set(aaString);
|
31 |
|
|
context.write(keyout, valueOut);
|
32 |
|
|
|
33 |
|
|
context.getCounter(this.getClass().getSimpleName(), aa.getTargetColumnFamily()).increment(1);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
while (iterator.hasNext()) {
|
37 |
|
|
final AtomicAction aa = AtomicAction.fromJSON(iterator.next().toString());
|
38 |
|
|
context.getCounter(this.getClass().getSimpleName(), String.format("ignored %s", aa.getTargetColumnFamily())).increment(1);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
}
|
42 |
|
|
}
|