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 | |
import java.util.Set; |
22 | |
|
23 | |
import org.apache.giraph.edge.Edge; |
24 | |
import org.apache.giraph.edge.EdgeFactory; |
25 | |
import org.apache.giraph.graph.Vertex; |
26 | |
import org.apache.giraph.io.gora.generated.GVertex; |
27 | |
import org.apache.hadoop.io.DoubleWritable; |
28 | |
import org.apache.hadoop.io.FloatWritable; |
29 | |
import org.apache.hadoop.io.LongWritable; |
30 | |
import org.apache.hadoop.mapreduce.InputSplit; |
31 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class GoraGVertexVertexInputFormat |
37 | |
extends GoraVertexInputFormat<LongWritable, DoubleWritable, |
38 | |
FloatWritable> { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public GoraGVertexVertexInputFormat() { |
44 | 0 | } |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
@Override |
53 | |
public GoraVertexReader createVertexReader( |
54 | |
InputSplit split, TaskAttemptContext context) throws IOException { |
55 | 0 | return new GoraGVertexVertexReader(); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | 0 | protected class GoraGVertexVertexReader extends GoraVertexReader { |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@Override |
69 | |
protected Vertex<LongWritable, DoubleWritable, FloatWritable> |
70 | |
transformVertex(Object goraObject) { |
71 | |
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex; |
72 | |
|
73 | 0 | vertex = getConf().createVertex(); |
74 | 0 | GVertex tmpGVertex = (GVertex) goraObject; |
75 | |
|
76 | 0 | LongWritable vrtxId = new LongWritable( |
77 | 0 | Long.parseLong(tmpGVertex.getVertexId().toString())); |
78 | 0 | DoubleWritable vrtxValue = new DoubleWritable( |
79 | 0 | tmpGVertex.getVertexValue()); |
80 | 0 | vertex.initialize(vrtxId, vrtxValue); |
81 | 0 | if (tmpGVertex.getEdges() != null && !tmpGVertex.getEdges().isEmpty()) { |
82 | 0 | Set<CharSequence> keyIt = tmpGVertex.getEdges().keySet(); |
83 | 0 | for (CharSequence key : keyIt) { |
84 | 0 | String keyVal = key.toString(); |
85 | 0 | String valVal = tmpGVertex.getEdges().get(key).toString(); |
86 | |
Edge<LongWritable, FloatWritable> edge; |
87 | 0 | if (!keyVal.contains("vertexId") && !keyVal.contains("value")) { |
88 | 0 | edge = EdgeFactory.create( |
89 | 0 | new LongWritable(Long.parseLong(keyVal)), |
90 | 0 | new FloatWritable(Float.parseFloat(valVal))); |
91 | 0 | vertex.addEdge(edge); |
92 | |
} |
93 | 0 | } |
94 | |
} |
95 | 0 | return vertex; |
96 | |
} |
97 | |
} |
98 | |
} |