1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.examples; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
|
23 | |
import org.apache.giraph.graph.Vertex; |
24 | |
import org.apache.giraph.io.formats.TextVertexOutputFormat; |
25 | |
import org.apache.hadoop.io.DoubleWritable; |
26 | |
import org.apache.hadoop.io.LongWritable; |
27 | |
import org.apache.hadoop.io.Text; |
28 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class VertexWithDoubleValueDoubleEdgeTextOutputFormat extends |
34 | |
TextVertexOutputFormat<LongWritable, DoubleWritable, DoubleWritable> { |
35 | |
@Override |
36 | |
public TextVertexWriter createVertexWriter(TaskAttemptContext context) |
37 | |
throws IOException, InterruptedException { |
38 | 0 | return new VertexWithDoubleValueWriter(); |
39 | |
} |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class VertexWithDoubleValueWriter extends TextVertexWriter { |
46 | |
@Override |
47 | |
public void writeVertex( |
48 | |
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex) |
49 | |
throws IOException, InterruptedException { |
50 | 0 | StringBuilder output = new StringBuilder(); |
51 | 0 | output.append(vertex.getId().get()); |
52 | 0 | output.append('\t'); |
53 | 0 | output.append(vertex.getValue().get()); |
54 | 0 | getRecordWriter().write(new Text(output.toString()), null); |
55 | 0 | } |
56 | |
} |
57 | |
} |