Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.propagation.communitytoresult;
2

    
3
import eu.dnetlib.data.mapreduce.hbase.propagation.Utils;
4
import eu.dnetlib.data.mapreduce.hbase.propagation.Value;
5

    
6
import eu.dnetlib.data.proto.*;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.apache.hadoop.hbase.client.Put;
10
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
11
import org.apache.hadoop.hbase.mapreduce.TableReducer;
12
import org.apache.hadoop.hbase.util.Bytes;
13
import org.apache.hadoop.io.Text;
14

    
15
import java.io.IOException;
16

    
17
import java.util.Iterator;
18

    
19
import static eu.dnetlib.data.mapreduce.hbase.propagation.PropagationConstants.*;
20

    
21

    
22
public class CommunityToResultReducer extends TableReducer<ImmutableBytesWritable, Text, ImmutableBytesWritable> {
23
    private static final Log log = LogFactory.getLog(CommunityToResultReducer.class); // NOPMD by marko on 11/24/08 5:02 PM
24
    private ImmutableBytesWritable keyOut;
25

    
26

    
27

    
28
    @Override
29
    protected void setup(final Context context) throws IOException, InterruptedException {
30
        super.setup(context);
31
        keyOut = new ImmutableBytesWritable();
32
    }
33

    
34

    
35
    @Override
36
    protected void reduce(ImmutableBytesWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
37
        Iterator<Text> it = values.iterator();
38
        final ResultProtos.Result.Metadata.Builder metadata = ResultProtos.Result.Metadata.newBuilder();
39
        while(it.hasNext()){
40
            Value v = Value.fromJson(it.next().toString());
41
            metadata.addContext(Utils.getContext(v.getValue(),v.getTrust()));
42

    
43
        }
44

    
45
        final Put put = new Put(Bytes.toBytes(key.toString())).add(Bytes.toBytes("result"), Bytes.toBytes("update_" + System.nanoTime()), Utils.getUpdate(metadata, key.toString()).toByteArray());
46
        keyOut.set(Bytes.toBytes(key.toString()));
47
        context.write(keyOut, put);
48
        context.getCounter(COUNTER_PROPAGATION, "added community to result").increment(1);
49

    
50

    
51
    }
52

    
53

    
54

    
55

    
56
}
57

    
(4-4/4)