1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.mapreduce.hbase.index;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.data.mapreduce.util.OafDecoder;
|
4 |
35128
|
claudio.at
|
import eu.dnetlib.data.mapreduce.util.OafHbaseUtils;
|
5 |
26600
|
sandro.lab
|
import eu.dnetlib.data.mapreduce.util.OafRowKeyDecoder;
|
6 |
53710
|
claudio.at
|
import eu.dnetlib.data.proto.KindProtos;
|
7 |
53684
|
claudio.at
|
import eu.dnetlib.data.proto.OafProtos;
|
8 |
|
|
import eu.dnetlib.data.proto.TypeProtos;
|
9 |
43428
|
alessia.ba
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
10 |
53684
|
claudio.at
|
import org.apache.hadoop.io.NullWritable;
|
11 |
43428
|
alessia.ba
|
import org.apache.hadoop.io.Text;
|
12 |
53684
|
claudio.at
|
import org.apache.hadoop.mapreduce.Counter;
|
13 |
43428
|
alessia.ba
|
import org.apache.hadoop.mapreduce.Reducer;
|
14 |
26600
|
sandro.lab
|
|
15 |
53684
|
claudio.at
|
public class InfospaceCountsReducer extends Reducer<Text, ImmutableBytesWritable, NullWritable, NullWritable> {
|
16 |
26600
|
sandro.lab
|
|
17 |
53710
|
claudio.at
|
public static final String ENTITY = KindProtos.Kind.entity.toString();
|
18 |
|
|
|
19 |
26600
|
sandro.lab
|
@Override
|
20 |
53684
|
claudio.at
|
protected void reduce(final Text key, final Iterable<ImmutableBytesWritable> values, final Context context) {
|
21 |
26600
|
sandro.lab
|
try {
|
22 |
53684
|
claudio.at
|
final OafRowKeyDecoder keyDecoder = OafRowKeyDecoder.decode(key.toString());
|
23 |
|
|
for (final ImmutableBytesWritable bytes : values) {
|
24 |
|
|
final OafDecoder decoder = OafHbaseUtils.decode(bytes);
|
25 |
|
|
final TypeProtos.Type type = keyDecoder.getType();
|
26 |
28094
|
claudio.at
|
|
27 |
53710
|
claudio.at
|
final OafProtos.Oaf oaf = decoder.getOaf();
|
28 |
|
|
|
29 |
53684
|
claudio.at
|
switch (decoder.getKind()) {
|
30 |
|
|
case entity:
|
31 |
53710
|
claudio.at
|
if (deletedByInference(oaf)) {
|
32 |
|
|
if (isInvisible(oaf)) {
|
33 |
|
|
incrementCounter(context, ENTITY, String.format("%s (deleted true / invisible true)", getEntityType(oaf, type)), 1);
|
34 |
|
|
} else {
|
35 |
|
|
incrementCounter(context, ENTITY, String.format("%s (deleted true / invisible false)", getEntityType(oaf, type)), 1);
|
36 |
|
|
}
|
37 |
|
|
} else {
|
38 |
|
|
|
39 |
|
|
if (isInvisible(oaf)) {
|
40 |
|
|
incrementCounter(context, ENTITY, String.format("%s (deleted false / invisible true)", getEntityType(oaf, type)), 1);
|
41 |
|
|
} else {
|
42 |
|
|
incrementCounter(context, ENTITY, String.format("%s (deleted false / invisible false)", getEntityType(oaf, type)), 1);
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
53684
|
claudio.at
|
break;
|
46 |
|
|
case relation:
|
47 |
53710
|
claudio.at
|
if (deletedByInference(oaf)) {
|
48 |
|
|
incrementCounter(context, String.format("%s (deleted true)", ENTITY), decoder.getCFQ(), 1);
|
49 |
|
|
} else {
|
50 |
|
|
incrementCounter(context, String.format("%s (deleted false)", ENTITY), decoder.getCFQ(), 1);
|
51 |
|
|
}
|
52 |
53684
|
claudio.at
|
break;
|
53 |
|
|
default:
|
54 |
|
|
throw new IllegalArgumentException("unknow type: " + decoder.getKind());
|
55 |
37353
|
claudio.at
|
}
|
56 |
26600
|
sandro.lab
|
}
|
57 |
53684
|
claudio.at
|
} catch (final Throwable e) {
|
58 |
37336
|
claudio.at
|
context.getCounter("error", e.getClass().getName()).increment(1);
|
59 |
26600
|
sandro.lab
|
throw new RuntimeException(e);
|
60 |
|
|
}
|
61 |
53684
|
claudio.at
|
}
|
62 |
37336
|
claudio.at
|
|
63 |
53684
|
claudio.at
|
private void incrementCounter(final Reducer.Context context, final String k, final String t, final int n) {
|
64 |
|
|
getCounter(context, k, t).increment(n);
|
65 |
26600
|
sandro.lab
|
}
|
66 |
|
|
|
67 |
53684
|
claudio.at
|
private Counter getCounter(final Reducer.Context context, final String k, final String t) {
|
68 |
|
|
return context.getCounter(k, t);
|
69 |
|
|
}
|
70 |
26600
|
sandro.lab
|
|
71 |
53684
|
claudio.at
|
private String getEntityType(final OafProtos.Oaf oaf, final TypeProtos.Type type) {
|
72 |
|
|
switch (type) {
|
73 |
|
|
case result:
|
74 |
|
|
return oaf.getEntity().getResult().getMetadata().getResulttype().getClassid();
|
75 |
37353
|
claudio.at
|
default:
|
76 |
53684
|
claudio.at
|
return type.toString();
|
77 |
26600
|
sandro.lab
|
}
|
78 |
|
|
}
|
79 |
37353
|
claudio.at
|
|
80 |
53710
|
claudio.at
|
private boolean deletedByInference(final OafProtos.Oaf oaf) {
|
81 |
|
|
return oaf.getDataInfo().getDeletedbyinference();
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
private boolean isInvisible(final OafProtos.Oaf oaf) {
|
85 |
|
|
return oaf.getDataInfo().getInvisible();
|
86 |
|
|
}
|
87 |
|
|
|
88 |
26600
|
sandro.lab
|
}
|