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 org.apache.giraph.graph.BasicVertex; |
22 | |
import org.apache.giraph.graph.VertexWriter; |
23 | |
import org.apache.giraph.lib.TextVertexOutputFormat; |
24 | |
import org.apache.hadoop.io.IntWritable; |
25 | |
import org.apache.hadoop.io.NullWritable; |
26 | |
import org.apache.hadoop.io.Text; |
27 | |
import org.apache.hadoop.mapreduce.RecordWriter; |
28 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
29 | |
|
30 | |
import java.io.IOException; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class VertexWithComponentTextOutputFormat extends |
40 | |
TextVertexOutputFormat<IntWritable, IntWritable, NullWritable> { |
41 | |
@Override |
42 | |
public VertexWriter<IntWritable, IntWritable, NullWritable> |
43 | |
createVertexWriter(TaskAttemptContext context) |
44 | |
throws IOException, InterruptedException { |
45 | 0 | RecordWriter<Text, Text> recordWriter = |
46 | |
textOutputFormat.getRecordWriter(context); |
47 | 0 | return new VertexWithComponentWriter(recordWriter); |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public static class VertexWithComponentWriter extends |
54 | |
TextVertexOutputFormat.TextVertexWriter<IntWritable, IntWritable, |
55 | |
NullWritable> { |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public VertexWithComponentWriter(RecordWriter<Text, Text> writer) { |
62 | 0 | super(writer); |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public void writeVertex(BasicVertex<IntWritable, IntWritable, |
67 | |
NullWritable, ?> vertex) throws IOException, |
68 | |
InterruptedException { |
69 | 0 | StringBuilder output = new StringBuilder(); |
70 | 0 | output.append(vertex.getVertexId().get()); |
71 | 0 | output.append('\t'); |
72 | 0 | output.append(vertex.getVertexValue().get()); |
73 | 0 | getRecordWriter().write(new Text(output.toString()), null); |
74 | 0 | } |
75 | |
} |
76 | |
} |