1
|
package eu.dnetlib.data.mapreduce.hbase.propagation.orcidthroughproducts;
|
2
|
|
3
|
import com.googlecode.protobuf.format.JsonFormat;
|
4
|
import eu.dnetlib.data.mapreduce.hbase.propagation.NotValidResultSequenceException;
|
5
|
import eu.dnetlib.data.mapreduce.hbase.propagation.ResultIterator;
|
6
|
import eu.dnetlib.data.mapreduce.hbase.propagation.projecttoresult.PropagationProjectToResultReducer;
|
7
|
import eu.dnetlib.data.mapreduce.hbase.propagation.projecttoresult.ResultProjectIterator;
|
8
|
import eu.dnetlib.data.mapreduce.util.OafRowKeyDecoder;
|
9
|
import eu.dnetlib.data.proto.OafProtos;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.apache.hadoop.hbase.client.Put;
|
13
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
14
|
import org.apache.hadoop.hbase.mapreduce.TableReducer;
|
15
|
import org.apache.hadoop.hbase.util.Bytes;
|
16
|
import org.apache.hadoop.io.Text;
|
17
|
|
18
|
import java.io.IOException;
|
19
|
import java.util.List;
|
20
|
|
21
|
import static eu.dnetlib.data.mapreduce.hbase.propagation.PropagationConstants.COUNTER_PROPAGATION;
|
22
|
import static eu.dnetlib.data.mapreduce.hbase.propagation.PropagationConstants.RELATION;
|
23
|
|
24
|
public class PropagationOrcidToResultReducer extends TableReducer<ImmutableBytesWritable, Text, ImmutableBytesWritable> {
|
25
|
private static final Log log = LogFactory.getLog(PropagationOrcidToResultReducer.class); // NOPMD by marko on 11/24/08 5:02 PM
|
26
|
private ImmutableBytesWritable keyOut;
|
27
|
|
28
|
|
29
|
|
30
|
@Override
|
31
|
protected void setup(final Context context) throws IOException, InterruptedException {
|
32
|
super.setup(context);
|
33
|
keyOut = new ImmutableBytesWritable();
|
34
|
}
|
35
|
|
36
|
|
37
|
@Override
|
38
|
protected void reduce(ImmutableBytesWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
|
39
|
ResultIterator rh = null;
|
40
|
try {
|
41
|
rh = new ResultOrcidIterator(values, Bytes.toString(key.copyBytes()));
|
42
|
} catch (NotValidResultSequenceException e) {
|
43
|
context.getCounter(COUNTER_PROPAGATION, e.getMessage()).increment(1);
|
44
|
return;
|
45
|
}
|
46
|
|
47
|
while (rh.hasNext()) {
|
48
|
List<OafProtos.Oaf> oaf_list = rh.next();
|
49
|
if(oaf_list != null){
|
50
|
for (OafProtos.Oaf oaf : oaf_list) {
|
51
|
byte[] targetRowKey = Bytes.toBytes(oaf.getEntity().getId());
|
52
|
final Put put = new Put(targetRowKey).add(Bytes.toBytes("result"), Bytes.toBytes("update_" + System.nanoTime()), oaf.toByteArray());
|
53
|
keyOut.set(targetRowKey);
|
54
|
context.write(keyOut, put);
|
55
|
context.getCounter(COUNTER_PROPAGATION, "added orcid to product").increment(1);
|
56
|
|
57
|
}
|
58
|
|
59
|
}
|
60
|
|
61
|
}
|
62
|
|
63
|
|
64
|
|
65
|
}
|
66
|
|
67
|
|
68
|
|
69
|
}
|