1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.io.formats; |
20 | |
|
21 | |
import org.apache.giraph.utils.IntPair; |
22 | |
import org.apache.hadoop.io.IntWritable; |
23 | |
import org.apache.hadoop.io.Text; |
24 | |
import org.apache.hadoop.io.Writable; |
25 | |
import org.apache.hadoop.mapreduce.InputSplit; |
26 | |
import org.apache.hadoop.mapreduce.TaskAttemptContext; |
27 | |
|
28 | |
import java.io.IOException; |
29 | |
import java.util.regex.Pattern; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class IntIntTextVertexValueInputFormat<E extends Writable> extends |
40 | |
TextVertexValueInputFormat<IntWritable, IntWritable, E> { |
41 | |
|
42 | 0 | private static final Pattern SEPARATOR = Pattern.compile("[\t ]"); |
43 | |
|
44 | |
@Override |
45 | |
public TextVertexValueReader createVertexValueReader( |
46 | |
InputSplit split, TaskAttemptContext context) throws IOException { |
47 | 0 | return new IntIntTextVertexValueReader(); |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | public class IntIntTextVertexValueReader extends |
55 | |
TextVertexValueReaderFromEachLineProcessed<IntPair> { |
56 | |
|
57 | |
@Override |
58 | |
protected IntPair preprocessLine(Text line) throws IOException { |
59 | 0 | String[] tokens = SEPARATOR.split(line.toString()); |
60 | 0 | return new IntPair(Integer.parseInt(tokens[0]), |
61 | 0 | Integer.parseInt(tokens[1])); |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
protected IntWritable getId(IntPair data) throws IOException { |
66 | 0 | return new IntWritable(data.getFirst()); |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
protected IntWritable getValue(IntPair data) throws IOException { |
71 | 0 | return new IntWritable(data.getSecond()); |
72 | |
} |
73 | |
} |
74 | |
} |