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.VertexInputFormat; |
22 | |
import org.apache.giraph.graph.VertexReader; |
23 | |
import org.apache.hadoop.io.Writable; |
24 | |
import org.apache.hadoop.io.WritableComparable; |
25 | |
import org.apache.hadoop.mapreduce.InputSplit; |
26 | |
import org.apache.hadoop.mapreduce.JobContext; |
27 | |
import org.apache.hadoop.mapreduce.RecordReader; |
28 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
29 | |
import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat; |
30 | |
|
31 | |
import java.io.IOException; |
32 | |
import java.util.List; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@SuppressWarnings("rawtypes") |
44 | 0 | public class SequenceFileVertexInputFormat<I extends WritableComparable, |
45 | |
V extends Writable, E extends Writable, M extends Writable, |
46 | |
X extends BasicVertex<I, V, E, M>> |
47 | |
extends VertexInputFormat<I, V, E, M> { |
48 | |
|
49 | 0 | protected SequenceFileInputFormat<I, X> sequenceFileInputFormat = |
50 | |
new SequenceFileInputFormat<I, X>(); |
51 | |
|
52 | |
@Override |
53 | |
public List<InputSplit> getSplits(JobContext context, int numWorkers) |
54 | |
throws IOException, InterruptedException { |
55 | 0 | return sequenceFileInputFormat.getSplits(context); |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public VertexReader<I, V, E, M> createVertexReader(InputSplit split, |
60 | |
TaskAttemptContext context) throws IOException { |
61 | 0 | return new SequenceFileVertexReader<I, V, E, M, X>( |
62 | |
sequenceFileInputFormat.createRecordReader(split, context)); |
63 | |
} |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | public static class SequenceFileVertexReader<I extends WritableComparable, |
75 | |
V extends Writable, E extends Writable, M extends Writable, |
76 | |
X extends BasicVertex<I, V, E, M>> |
77 | |
implements VertexReader<I, V, E, M> { |
78 | |
|
79 | |
private final RecordReader<I, X> recordReader; |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | 0 | public SequenceFileVertexReader(RecordReader<I, X> recordReader) { |
87 | 0 | this.recordReader = recordReader; |
88 | 0 | } |
89 | |
|
90 | |
@Override public void initialize(InputSplit inputSplit, |
91 | |
TaskAttemptContext context) throws IOException, InterruptedException { |
92 | 0 | recordReader.initialize(inputSplit, context); |
93 | 0 | } |
94 | |
|
95 | |
@Override public boolean nextVertex() throws IOException, |
96 | |
InterruptedException { |
97 | 0 | return recordReader.nextKeyValue(); |
98 | |
} |
99 | |
|
100 | |
@Override public BasicVertex<I, V, E, M> getCurrentVertex() |
101 | |
throws IOException, InterruptedException { |
102 | 0 | return recordReader.getCurrentValue(); |
103 | |
} |
104 | |
|
105 | |
|
106 | |
@Override public void close() throws IOException { |
107 | 0 | recordReader.close(); |
108 | 0 | } |
109 | |
|
110 | |
@Override public float getProgress() throws IOException, |
111 | |
InterruptedException { |
112 | 0 | return recordReader.getProgress(); |
113 | |
} |
114 | |
} |
115 | |
} |