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