Project

General

Profile

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

    
3
import java.io.IOException;
4
import java.util.Map;
5

    
6
import eu.dnetlib.data.mapreduce.JobParams;
7
import eu.dnetlib.data.mapreduce.util.DedupUtils;
8
import eu.dnetlib.data.proto.TypeProtos.Type;
9
import eu.dnetlib.pace.config.DedupConfig;
10
import org.apache.hadoop.hbase.client.Delete;
11
import org.apache.hadoop.hbase.client.Durability;
12
import org.apache.hadoop.hbase.client.Result;
13
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
14
import org.apache.hadoop.hbase.mapreduce.TableMapper;
15
import org.apache.hadoop.io.Writable;
16

    
17
public class DedupDeleteRelMapper extends TableMapper<ImmutableBytesWritable, Writable> {
18

    
19
	private DedupConfig dedupConf;
20

    
21
	private ImmutableBytesWritable outKey;
22

    
23
	@Override
24
	protected void setup(final Context context) throws IOException, InterruptedException {
25
		dedupConf = DedupConfig.load(context.getConfiguration().get(JobParams.DEDUP_CONF));
26
		System.out.println("dedup findRoots mapper\nwf conf: " + dedupConf.toString());
27

    
28
		outKey = new ImmutableBytesWritable();
29
	}
30

    
31
	@Override
32
	protected void map(final ImmutableBytesWritable rowkey, final Result value, final Context context) throws IOException, InterruptedException {
33
		// System.out.println("Find root mapping: " + new String(rowkey.copyBytes()));
34

    
35
		final Type type = Type.valueOf(dedupConf.getWf().getEntityType());
36

    
37
		deleteRels(rowkey, context, value, DedupUtils.getSimilarityCFBytes(type));
38
		deleteRels(rowkey, context, value, DedupUtils.getDedupCF_mergedInBytes(type));
39
		deleteRels(rowkey, context, value, DedupUtils.getDedupCF_mergesBytes(type));
40
	}
41

    
42
	private void deleteRels(final ImmutableBytesWritable rowkey, final Context context, final Result value, final byte[] cf)
43
			throws IOException, InterruptedException {
44

    
45
		final Map<byte[], byte[]> rels = value.getFamilyMap(cf);
46

    
47
		if ((rels != null) && !rels.isEmpty()) {
48

    
49
			final byte[] row = rowkey.copyBytes();
50
			final Delete delete = new Delete(row);
51
			delete.setDurability(Durability.USE_DEFAULT);
52

    
53
			delete.deleteFamily(cf);
54

    
55
			outKey.set(row);
56
			context.write(outKey, delete);
57
			context.getCounter(dedupConf.getWf().getEntityType(), new String(cf) + " deleted").increment(rels.size());
58
		}
59
	}
60
}
(3-3/16)