Revision 56866
Added by Miriam Baglioni over 4 years ago
CommunityToResultReducer.java | ||
---|---|---|
14 | 14 |
|
15 | 15 |
import java.io.IOException; |
16 | 16 |
|
17 |
import java.util.HashSet; |
|
17 | 18 |
import java.util.Iterator; |
19 |
import java.util.Set; |
|
18 | 20 |
|
19 | 21 |
import static eu.dnetlib.data.mapreduce.hbase.propagation.PropagationConstants.*; |
20 | 22 |
|
... | ... | |
36 | 38 |
protected void reduce(ImmutableBytesWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException { |
37 | 39 |
Iterator<Text> it = values.iterator(); |
38 | 40 |
final ResultProtos.Result.Metadata.Builder metadata = ResultProtos.Result.Metadata.newBuilder(); |
41 |
Set<String> added_context = new HashSet<>(); |
|
39 | 42 |
while(it.hasNext()){ |
40 | 43 |
Value v = Value.fromJson(it.next().toString()); |
41 |
metadata.addContext(Utils.getContext(v.getValue(),v.getTrust())); |
|
42 |
|
|
44 |
if (!added_context.contains(v.getValue())) { |
|
45 |
metadata.addContext(Utils.getContext(v.getValue(), v.getTrust(), CLASS_COMMUNITY_ID, DATA_INFO_TYPE, CLASS_COMMUNITY_NAME)); |
|
46 |
added_context.add(v.getValue()); |
|
47 |
} |
|
43 | 48 |
} |
44 | 49 |
|
45 |
final Put put = new Put(Bytes.toBytes(key.toString())).add(Bytes.toBytes("result"), Bytes.toBytes("update_" + System.nanoTime()), Utils.getUpdate(metadata, key.toString()).toByteArray());
|
|
46 |
keyOut.set(Bytes.toBytes(key.toString()));
|
|
50 |
final Put put = new Put(key.get()).add(Bytes.toBytes("result"), Bytes.toBytes("update_" + System.nanoTime()), Utils.getUpdate(metadata, Bytes.toString(key.get())).toByteArray());
|
|
51 |
keyOut.set(key.get());
|
|
47 | 52 |
context.write(keyOut, put); |
48 | 53 |
context.getCounter(COUNTER_PROPAGATION, "added community to result").increment(1); |
49 | 54 |
|
Also available in: Unified diff
added classname information. Save the same context just once for the update in h-base