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.io.formats;
19
20 import org.apache.giraph.edge.Edge;
21 import org.apache.giraph.edge.EdgeFactory;
22 import org.apache.hadoop.io.DoubleWritable;
23 import org.apache.hadoop.io.LongWritable;
24 import org.apache.hadoop.mapreduce.InputSplit;
25 import org.apache.hadoop.mapreduce.TaskAttemptContext;
26
27 /**
28 * InputFormat for reading graphs stored as (ordered) adjacency lists
29 * with the vertex ids longs and the vertex values and edges doubles.
30 * For example:
31 * 22 0.1 45 0.3 99 0.44
32 * to repesent a vertex with id 22, value of 0.1 and edges to nodes 45 and 99,
33 * with values of 0.3 and 0.44, respectively.
34 */
35 public class LongDoubleDoubleAdjacencyListVertexInputFormat
36 extends AdjacencyListTextVertexInputFormat<LongWritable, DoubleWritable,
37 DoubleWritable> {
38
39 @Override
40 public AdjacencyListTextVertexReader createVertexReader(InputSplit split,
41 TaskAttemptContext context) {
42 return new LongDoubleDoubleAdjacencyListVertexReader(null);
43 }
44
45 /**
46 * VertexReader associated with
47 * {@link LongDoubleDoubleAdjacencyListVertexInputFormat}.
48 */
49 protected class LongDoubleDoubleAdjacencyListVertexReader extends
50 AdjacencyListTextVertexReader {
51
52 /**
53 * Constructor with
54 * {@link AdjacencyListTextVertexInputFormat.LineSanitizer}.
55 *
56 * @param lineSanitizer the sanitizer to use for reading
57 */
58 public LongDoubleDoubleAdjacencyListVertexReader(LineSanitizer
59 lineSanitizer) {
60 super(lineSanitizer);
61 }
62
63 @Override
64 public LongWritable decodeId(String s) {
65 return new LongWritable(Long.parseLong(s));
66 }
67
68 @Override
69 public DoubleWritable decodeValue(String s) {
70 return new DoubleWritable(Double.parseDouble(s));
71 }
72
73 @Override
74 public Edge<LongWritable, DoubleWritable> decodeEdge(String s1, String s2) {
75 return EdgeFactory.create(new LongWritable(Long.parseLong(s1)),
76 new DoubleWritable(Double.parseDouble(s2)));
77 }
78 }
79
80 }