Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TextDoubleDoubleAdjacencyListVertexInputFormat |
|
| 1.0;1 | ||||
TextDoubleDoubleAdjacencyListVertexInputFormat$VertexReader |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
18 | package org.apache.giraph.lib; | |
19 | ||
20 | import org.apache.giraph.graph.Edge; | |
21 | import org.apache.hadoop.io.DoubleWritable; | |
22 | import org.apache.hadoop.io.LongWritable; | |
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.RecordReader; | |
27 | import org.apache.hadoop.mapreduce.TaskAttemptContext; | |
28 | ||
29 | import java.io.IOException; | |
30 | ||
31 | /** | |
32 | * Class to read graphs stored as adjacency lists with ids represented by | |
33 | * Strings and values as doubles. This is a good inputformat for reading | |
34 | * graphs where the id types do not matter and can be stashed in a String. | |
35 | * | |
36 | * @param <M> Message type. | |
37 | */ | |
38 | 0 | public class TextDoubleDoubleAdjacencyListVertexInputFormat<M extends Writable> |
39 | extends TextVertexInputFormat<Text, DoubleWritable, DoubleWritable, M> { | |
40 | ||
41 | ||
42 | /** | |
43 | * Vertex reader used with | |
44 | * {@link TextDoubleDoubleAdjacencyListVertexInputFormat} | |
45 | * | |
46 | * @param <M> Message type. | |
47 | */ | |
48 | 0 | static class VertexReader<M extends Writable> extends |
49 | AdjacencyListVertexReader<Text, DoubleWritable, DoubleWritable, M> { | |
50 | /** | |
51 | * Constructor without sanitzer. | |
52 | * | |
53 | * @param lineRecordReader Internal reader. | |
54 | */ | |
55 | VertexReader(RecordReader<LongWritable, Text> lineRecordReader) { | |
56 | 0 | super(lineRecordReader); |
57 | 0 | } |
58 | ||
59 | /** | |
60 | * Constructor with {@link LineRecordReader} | |
61 | * | |
62 | * @param lineRecordReader Internal reader. | |
63 | * @param sanitizer Sanitizer of the lines. | |
64 | */ | |
65 | VertexReader(RecordReader<LongWritable, Text> lineRecordReader, | |
66 | LineSanitizer sanitizer) { | |
67 | 0 | super(lineRecordReader, sanitizer); |
68 | 0 | } |
69 | ||
70 | @Override | |
71 | public void decodeId(String s, Text id) { | |
72 | 0 | id.set(s); |
73 | 0 | } |
74 | ||
75 | @Override | |
76 | public void decodeValue(String s, DoubleWritable value) { | |
77 | 0 | value.set(Double.valueOf(s)); |
78 | 0 | } |
79 | ||
80 | @Override | |
81 | public void decodeEdge(String s1, String s2, | |
82 | Edge<Text, DoubleWritable> textIntWritableEdge) { | |
83 | 0 | textIntWritableEdge.setDestVertexId(new Text(s1)); |
84 | 0 | textIntWritableEdge.setEdgeValue(new DoubleWritable(Double.valueOf(s2))); |
85 | 0 | } |
86 | } | |
87 | ||
88 | @Override | |
89 | public org.apache.giraph.graph.VertexReader<Text, DoubleWritable, | |
90 | DoubleWritable, M> createVertexReader(InputSplit split, | |
91 | TaskAttemptContext context) throws IOException { | |
92 | 0 | return new VertexReader<M>(textInputFormat.createRecordReader( |
93 | split, context)); | |
94 | } | |
95 | } |