Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LongDoubleDoubleAdjacencyListVertexInputFormat |
|
| 1.0;1 | ||||
LongDoubleDoubleAdjacencyListVertexInputFormat$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 | * InputFormat for reading graphs stored as (ordered) adjacency lists | |
33 | * with the vertex ids longs and the vertex values and edges doubles. | |
34 | * For example: | |
35 | * 22 0.1 45 0.3 99 0.44 | |
36 | * to repesent a vertex with id 22, value of 0.1 and edges to nodes 45 and 99, | |
37 | * with values of 0.3 and 0.44, respectively. | |
38 | * | |
39 | * @param <M> Message data | |
40 | */ | |
41 | 0 | public class LongDoubleDoubleAdjacencyListVertexInputFormat<M extends Writable> |
42 | extends TextVertexInputFormat<LongWritable, DoubleWritable, | |
43 | DoubleWritable, M> { | |
44 | ||
45 | /** | |
46 | * VertexReader associated with | |
47 | * {@link LongDoubleDoubleAdjacencyListVertexInputFormat}. | |
48 | * | |
49 | * @param <M> Message data. | |
50 | */ | |
51 | 0 | static class VertexReader<M extends Writable> extends |
52 | AdjacencyListVertexReader<LongWritable, DoubleWritable, | |
53 | DoubleWritable, M> { | |
54 | ||
55 | /** | |
56 | * Constructor with Line record reader. | |
57 | * | |
58 | * @param lineRecordReader Reader to internally use. | |
59 | */ | |
60 | VertexReader(RecordReader<LongWritable, Text> lineRecordReader) { | |
61 | 0 | super(lineRecordReader); |
62 | 0 | } |
63 | ||
64 | /** | |
65 | * Constructor with Line record reader and sanitizer. | |
66 | * | |
67 | * @param lineRecordReader Reader to internally use. | |
68 | * @param sanitizer Line sanitizer. | |
69 | */ | |
70 | VertexReader(RecordReader<LongWritable, Text> lineRecordReader, | |
71 | LineSanitizer sanitizer) { | |
72 | 0 | super(lineRecordReader, sanitizer); |
73 | 0 | } |
74 | ||
75 | @Override | |
76 | public void decodeId(String s, LongWritable id) { | |
77 | 0 | id.set(Long.valueOf(s)); |
78 | 0 | } |
79 | ||
80 | @Override | |
81 | public void decodeValue(String s, DoubleWritable value) { | |
82 | 0 | value.set(Double.valueOf(s)); |
83 | 0 | } |
84 | ||
85 | @Override | |
86 | public void decodeEdge( | |
87 | String s1, | |
88 | String s2, | |
89 | Edge<LongWritable, DoubleWritable> textIntWritableEdge) { | |
90 | 0 | textIntWritableEdge.setDestVertexId(new LongWritable(Long.valueOf(s1))); |
91 | 0 | textIntWritableEdge.setEdgeValue(new DoubleWritable(Double.valueOf(s2))); |
92 | 0 | } |
93 | } | |
94 | ||
95 | @Override | |
96 | public org.apache.giraph.graph.VertexReader<LongWritable, | |
97 | DoubleWritable, DoubleWritable, M> createVertexReader( | |
98 | InputSplit split, | |
99 | TaskAttemptContext context) throws IOException { | |
100 | 0 | return new VertexReader<M>(textInputFormat.createRecordReader( |
101 | split, context)); | |
102 | } | |
103 | } |