1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.giraph.io.gora;
1920import java.io.IOException;
2122import org.apache.giraph.edge.Edge;
23import org.apache.giraph.edge.EdgeFactory;
24import org.apache.giraph.io.gora.generated.GEdge;
25import org.apache.hadoop.io.FloatWritable;
26import org.apache.hadoop.io.LongWritable;
27import org.apache.hadoop.mapreduce.InputSplit;
28import org.apache.hadoop.mapreduce.TaskAttemptContext;
2930/**31 * Example implementation of a specific reader for a generated data bean.32 */33publicclassGoraGEdgeEdgeInputFormat34extends GoraEdgeInputFormat<LongWritable, FloatWritable> {
3536/**37 * Default constructor38 */39publicGoraGEdgeEdgeInputFormat() {
40 }
4142/**43 * Creates specific vertex reader to be used inside Hadoop.44 * @param split split to be read.45 * @param context JobContext to be used.46 * @return GoraEdgeReader Edge reader to be used by Hadoop.47 */48 @Override
49publicGoraEdgeReader createEdgeReader(
50 InputSplit split, TaskAttemptContext context) throws IOException {
51returnnewGoraGEdgeEdgeReader();
52 }
5354/**55 * Gora edge reader56 */57protectedclassGoraGEdgeEdgeReaderextendsGoraEdgeReader {
5859/** source vertex of the edge */60private LongWritable sourceId;
6162/**63 * Transforms a GoraObject into an Edge object.64 * @param goraObject Object from Gora to be translated.65 * @return Edge Result from transforming the gora object.66 */67 @Override
68protected Edge<LongWritable, FloatWritable> transformEdge
69 (Object goraObject) {
70 Edge<LongWritable, FloatWritable> edge = null;
71GEdge goraEdge = (GEdge) goraObject;
72this.sourceId = new LongWritable();
73this.sourceId.set(Long.parseLong(goraEdge.getVertexInId().toString()));
74 edge = EdgeFactory.create(
75new LongWritable(
76 Long.parseLong(goraEdge.getVertexOutId().toString())),
77new FloatWritable(goraEdge.getEdgeWeight()));
78return edge;
79 }
8081/**82 * Gets the currentSourceId for the edge.83 * @return LongWritable currentSourceId for the edge.84 */85 @Override
86public LongWritable getCurrentSourceId() throws IOException,
87 InterruptedException {
88returnthis.sourceId;
89 }
90 }
91 }