1
|
package eu.dnetlib.data.mapreduce.hbase.propagation.projecttoresult;
|
2
|
|
3
|
import eu.dnetlib.data.mapreduce.hbase.propagation.NotValidResultSequenceException;
|
4
|
import eu.dnetlib.data.mapreduce.hbase.propagation.ResultIterator;
|
5
|
import eu.dnetlib.data.proto.*;
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.apache.hadoop.hbase.client.Put;
|
9
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
10
|
import org.apache.hadoop.hbase.mapreduce.TableReducer;
|
11
|
import org.apache.hadoop.hbase.util.Bytes;
|
12
|
import org.apache.hadoop.io.Text;
|
13
|
|
14
|
import java.io.IOException;
|
15
|
|
16
|
import static eu.dnetlib.data.mapreduce.hbase.propagation.PropagationConstants.*;
|
17
|
|
18
|
public class PropagationProjectToResultReducer extends TableReducer<ImmutableBytesWritable, Text, ImmutableBytesWritable> {
|
19
|
private static final Log log = LogFactory.getLog(PropagationProjectToResultReducer.class); // NOPMD by marko on 11/24/08 5:02 PM
|
20
|
private ImmutableBytesWritable keyOut;
|
21
|
|
22
|
|
23
|
|
24
|
@Override
|
25
|
protected void setup(final Context context) throws IOException, InterruptedException {
|
26
|
super.setup(context);
|
27
|
keyOut = new ImmutableBytesWritable();
|
28
|
}
|
29
|
|
30
|
|
31
|
@Override
|
32
|
protected void reduce(ImmutableBytesWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
|
33
|
ResultIterator rh = null;
|
34
|
try {
|
35
|
rh = new ResultProjectIterator(values,Bytes.toString(key.copyBytes()));
|
36
|
} catch (NotValidResultSequenceException e) {
|
37
|
context.getCounter(COUNTER_PROPAGATION,e.getMessage()).increment(1);
|
38
|
return;
|
39
|
}
|
40
|
while(rh.hasNext()){
|
41
|
for(OafProtos.Oaf oaf:rh.next()){
|
42
|
final String source = oaf.getRel().getSource();
|
43
|
final Put put = new Put(Bytes.toBytes(source)).add(Bytes.toBytes(RELATION + oaf.getRel().getRelClass()),Bytes.toBytes(oaf.getRel().getTarget()),oaf.toByteArray());
|
44
|
keyOut.set(Bytes.toBytes(source));
|
45
|
context.write(keyOut, put);
|
46
|
|
47
|
}
|
48
|
context.getCounter(COUNTER_PROPAGATION,"Added relation to project").increment(1);
|
49
|
}
|
50
|
|
51
|
}
|
52
|
|
53
|
|
54
|
|
55
|
|
56
|
|
57
|
}
|