1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.io.gora; |
19 | |
|
20 | |
import java.io.IOException; |
21 | |
|
22 | |
import org.apache.giraph.edge.Edge; |
23 | |
import org.apache.giraph.io.gora.generated.GEdgeResult; |
24 | |
import org.apache.gora.persistency.Persistent; |
25 | |
import org.apache.hadoop.io.DoubleWritable; |
26 | |
import org.apache.hadoop.io.FloatWritable; |
27 | |
import org.apache.hadoop.io.LongWritable; |
28 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class GoraGEdgeEdgeOutputFormat |
34 | |
extends GoraEdgeOutputFormat<LongWritable, DoubleWritable, |
35 | |
FloatWritable> { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public GoraGEdgeEdgeOutputFormat() { |
41 | 0 | } |
42 | |
|
43 | |
@Override |
44 | |
public GoraEdgeWriter createEdgeWriter( |
45 | |
TaskAttemptContext context) throws IOException, InterruptedException { |
46 | 0 | return new GoraGEdgeEdgeWriter(); |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 0 | protected class GoraGEdgeEdgeWriter |
53 | |
extends GoraEdgeWriter { |
54 | |
|
55 | |
@Override |
56 | |
protected Persistent getGoraEdge(LongWritable srcId, |
57 | |
DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) { |
58 | 0 | GEdgeResult tmpGEdge = new GEdgeResult(); |
59 | 0 | tmpGEdge.setEdgeId(srcId.toString()); |
60 | 0 | tmpGEdge.setEdgeWeight(edge.getValue().get()); |
61 | 0 | tmpGEdge.setVertexOutId(edge.getTargetVertexId().toString()); |
62 | 0 | getLogger().debug("GoraObject created: " + tmpGEdge.toString()); |
63 | 0 | return tmpGEdge; |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
protected Object getGoraKey(LongWritable srcId, |
68 | |
DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) { |
69 | 0 | String goraKey = String.valueOf( |
70 | 0 | edge.getTargetVertexId().get() + edge.getValue().get()); |
71 | 0 | return goraKey; |
72 | |
} |
73 | |
|
74 | |
} |
75 | |
} |