1
|
package eu.dnetlib.data.mapreduce.hbase.dedup;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.Arrays;
|
5
|
import java.util.List;
|
6
|
|
7
|
import org.apache.hadoop.hbase.KeyValue;
|
8
|
import org.apache.hadoop.hbase.client.Durability;
|
9
|
import org.apache.hadoop.hbase.client.Put;
|
10
|
import org.apache.hadoop.hbase.client.Result;
|
11
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
12
|
import org.apache.hadoop.hbase.mapreduce.TableMapper;
|
13
|
import org.apache.hadoop.hbase.util.Bytes;
|
14
|
import org.apache.hadoop.io.Text;
|
15
|
|
16
|
import eu.dnetlib.data.mapreduce.JobParams;
|
17
|
import eu.dnetlib.data.mapreduce.util.DedupUtils;
|
18
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
19
|
import eu.dnetlib.pace.config.DedupConfig;
|
20
|
|
21
|
public class DedupGrouperMapper extends TableMapper<Text, Put> {
|
22
|
|
23
|
public static final String COUNTER_GROUP = "dedup.grouper";
|
24
|
|
25
|
public static final String COUNTER_NAME = "written.rels";
|
26
|
|
27
|
private Text rowKey;
|
28
|
|
29
|
private DedupConfig dedupConf;
|
30
|
|
31
|
@Override
|
32
|
protected void setup(final Context context) throws IOException, InterruptedException {
|
33
|
rowKey = new Text();
|
34
|
|
35
|
dedupConf = DedupConfig.load(context.getConfiguration().get(JobParams.DEDUP_CONF));
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
protected void map(final ImmutableBytesWritable keyIn, final Result value, final Context context) throws IOException, InterruptedException {
|
40
|
|
41
|
final byte[] family = DedupUtils.getSimilarityCFBytes(Type.valueOf(dedupConf.getWf().getEntityType()));
|
42
|
final byte[] cellValue = Bytes.toBytes("");
|
43
|
|
44
|
final List<KeyValue> kvList = value.list();
|
45
|
// System.out.println("Grouper mapping " + kvList.size() + " rels for key: " + new String(keyIn.copyBytes()));
|
46
|
|
47
|
for (final KeyValue n : kvList) {
|
48
|
for (final KeyValue j : kvList) {
|
49
|
|
50
|
final byte[] nq = n.getQualifier();
|
51
|
final byte[] jq = j.getQualifier();
|
52
|
|
53
|
if (!Arrays.equals(nq, jq)) {
|
54
|
|
55
|
final Put put = new Put(nq).add(family, jq, cellValue);
|
56
|
put.setDurability(Durability.USE_DEFAULT);
|
57
|
rowKey.set(nq);
|
58
|
context.write(rowKey, put);
|
59
|
|
60
|
context.getCounter(COUNTER_GROUP, COUNTER_NAME).increment(1);
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
|
66
|
}
|