Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.dataexport;
2

    
3
import com.googlecode.protobuf.format.JsonFormat;
4
import eu.dnetlib.data.mapreduce.util.DedupUtils;
5
import eu.dnetlib.data.proto.OafProtos;
6
import eu.dnetlib.data.proto.TypeProtos;
7
import org.apache.hadoop.hbase.client.Result;
8
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
9
import org.apache.hadoop.hbase.mapreduce.TableMapper;
10
import org.apache.hadoop.io.Text;
11

    
12
import java.io.IOException;
13
import java.util.Map;
14

    
15
public class ExportDuplicatesMapper extends TableMapper<Text, Text> {
16

    
17
    private Text keyOut;
18
    private Text valueOut;
19

    
20
    @Override
21
    protected void setup(Context context) throws IOException, InterruptedException {
22
        keyOut = new Text("");
23
        valueOut = new Text();
24
    }
25

    
26
    @Override
27
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
28

    
29
        final Map<byte[], byte[]> mergedInMap = value.getFamilyMap(DedupUtils.getDedupCF_mergedInBytes(TypeProtos.Type.result));
30

    
31
        if (mergedInMap != null && !mergedInMap.isEmpty()) {
32
            final byte[] body = value.getValue("result".getBytes(), DedupUtils.BODY_B);
33

    
34
            if (body != null) {
35
                OafProtos.Oaf oaf = OafProtos.Oaf.parseFrom(body);
36
                valueOut.set(JsonFormat.printToString(oaf));
37
                context.write(keyOut, valueOut);
38
            }
39
        }
40

    
41
    }
42
}
(1-1/5)