Project

General

Profile

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

    
3
import com.googlecode.protobuf.format.JsonFormat;
4

    
5
import eu.dnetlib.data.mapreduce.hbase.propagation.Utils;
6
import eu.dnetlib.data.mapreduce.hbase.propagation.Value;
7

    
8
import eu.dnetlib.data.proto.ResultProtos;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

    
12
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
13
import org.apache.hadoop.hbase.util.Bytes;
14
import org.apache.hadoop.io.Text;
15
import org.apache.hadoop.mapreduce.Reducer;
16

    
17
import java.io.IOException;
18
import java.util.Iterator;
19

    
20

    
21
public class CommunityToResultFileReducer extends Reducer<ImmutableBytesWritable, Text, Text,Text> {
22

    
23
    private static final Log log = LogFactory.getLog(CommunityToResultFileReducer.class); // NOPMD by marko on 11/24/08 5:02 PM
24

    
25
    private Text keyOut;
26
    private Text outValue;
27

    
28

    
29
    @Override
30
    protected void setup(final Context context) throws IOException, InterruptedException {
31
        super.setup(context);
32
        keyOut = new Text("");
33
        outValue = new Text();
34
    }
35

    
36

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

    
45
        }
46
        keyOut.set(Bytes.toBytes(key.toString()));
47
        outValue.set(JsonFormat.printToString(Utils.getUpdate(metadata,key.toString())).getBytes());
48
        context.write(keyOut, outValue);
49

    
50

    
51
    }
52

    
53

    
54
}
(2-2/4)