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.Result;
|
12
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
13
|
import org.apache.hadoop.hbase.mapreduce.TableMapper;
|
14
|
import org.apache.hadoop.io.Writable;
|
15
|
|
16
|
public class DedupDeleteRelMapper extends TableMapper<ImmutableBytesWritable, Writable> {
|
17
|
|
18
|
private DedupConfig dedupConf;
|
19
|
|
20
|
private ImmutableBytesWritable outKey;
|
21
|
|
22
|
@Override
|
23
|
protected void setup(final Context context) throws IOException, InterruptedException {
|
24
|
dedupConf = DedupConfig.load(context.getConfiguration().get(JobParams.DEDUP_CONF));
|
25
|
System.out.println("dedup findRoots mapper\nwf conf: " + dedupConf.toString());
|
26
|
|
27
|
outKey = new ImmutableBytesWritable();
|
28
|
}
|
29
|
|
30
|
@Override
|
31
|
protected void map(final ImmutableBytesWritable rowkey, final Result value, final Context context) throws IOException, InterruptedException {
|
32
|
// System.out.println("Find root mapping: " + new String(rowkey.copyBytes()));
|
33
|
|
34
|
final Type type = Type.valueOf(dedupConf.getWf().getEntityType());
|
35
|
|
36
|
deleteRels(rowkey, context, value, DedupUtils.getSimilarityCFBytes(type));
|
37
|
deleteRels(rowkey, context, value, DedupUtils.getDedupCF_mergedInBytes(type));
|
38
|
deleteRels(rowkey, context, value, DedupUtils.getDedupCF_mergesBytes(type));
|
39
|
}
|
40
|
|
41
|
private void deleteRels(final ImmutableBytesWritable rowkey, final Context context, final Result value, final byte[] cf)
|
42
|
throws IOException, InterruptedException {
|
43
|
|
44
|
final Map<byte[], byte[]> rels = value.getFamilyMap(cf);
|
45
|
|
46
|
if ((rels != null) && !rels.isEmpty()) {
|
47
|
|
48
|
final byte[] row = rowkey.copyBytes();
|
49
|
final Delete delete = new Delete(row);
|
50
|
delete.setWriteToWAL(JobParams.WRITE_TO_WAL);
|
51
|
|
52
|
delete.deleteFamily(cf);
|
53
|
|
54
|
outKey.set(row);
|
55
|
context.write(outKey, delete);
|
56
|
context.getCounter(dedupConf.getWf().getEntityType(), new String(cf) + " deleted").increment(rels.size());
|
57
|
}
|
58
|
}
|
59
|
}
|