1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.lib; |
19 | |
|
20 | |
import org.apache.giraph.graph.BasicVertex; |
21 | |
import org.apache.giraph.graph.VertexWriter; |
22 | |
import org.apache.hadoop.io.Text; |
23 | |
import org.apache.hadoop.io.Writable; |
24 | |
import org.apache.hadoop.io.WritableComparable; |
25 | |
import org.apache.hadoop.mapreduce.RecordWriter; |
26 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
27 | |
|
28 | |
import java.io.IOException; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
@SuppressWarnings("rawtypes") |
41 | 0 | public class AdjacencyListTextVertexOutputFormat<I extends WritableComparable, |
42 | |
V extends Writable, E extends Writable> |
43 | |
extends TextVertexOutputFormat<I, V, E> { |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 0 | static class AdjacencyListVertexWriter<I extends WritableComparable, V extends |
53 | |
Writable, E extends Writable> extends TextVertexWriter<I, V, E> { |
54 | |
|
55 | |
public static final String LINE_TOKENIZE_VALUE = "output.delimiter"; |
56 | |
|
57 | |
public static final String LINE_TOKENIZE_VALUE_DEFAULT = "\t"; |
58 | |
|
59 | |
private String delimiter; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public AdjacencyListVertexWriter(RecordWriter<Text, Text> recordWriter) { |
67 | 0 | super(recordWriter); |
68 | 0 | } |
69 | |
|
70 | |
@Override |
71 | |
public void writeVertex(BasicVertex<I, V, E, ?> vertex) throws IOException, |
72 | |
InterruptedException { |
73 | 0 | if (delimiter == null) { |
74 | 0 | delimiter = getContext().getConfiguration() |
75 | |
.get(LINE_TOKENIZE_VALUE, LINE_TOKENIZE_VALUE_DEFAULT); |
76 | |
} |
77 | |
|
78 | 0 | StringBuffer sb = new StringBuffer(vertex.getVertexId().toString()); |
79 | 0 | sb.append(delimiter); |
80 | 0 | sb.append(vertex.getVertexValue().toString()); |
81 | |
|
82 | 0 | for (I edge : vertex) { |
83 | 0 | sb.append(delimiter).append(edge); |
84 | 0 | sb.append(delimiter).append(vertex.getEdgeValue(edge)); |
85 | |
} |
86 | |
|
87 | 0 | getRecordWriter().write(new Text(sb.toString()), null); |
88 | 0 | } |
89 | |
} |
90 | |
|
91 | |
@Override |
92 | |
public VertexWriter<I, V, E> createVertexWriter(TaskAttemptContext context) |
93 | |
throws IOException, InterruptedException { |
94 | 0 | return new AdjacencyListVertexWriter<I, V, E> |
95 | |
(textOutputFormat.getRecordWriter(context)); |
96 | |
} |
97 | |
} |