This project has retired. For details please refer to its Attic page.
GoraGEdgeEdgeOutputFormat xref
View Javadoc

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.gora;
19  
20  import java.io.IOException;
21  
22  import org.apache.giraph.edge.Edge;
23  import org.apache.giraph.io.gora.generated.GEdgeResult;
24  import org.apache.gora.persistency.Persistent;
25  import org.apache.hadoop.io.DoubleWritable;
26  import org.apache.hadoop.io.FloatWritable;
27  import org.apache.hadoop.io.LongWritable;
28  import org.apache.hadoop.mapreduce.TaskAttemptContext;
29  
30  /**
31   * Implementation of a specific writer for a generated data bean.
32   */
33  public class GoraGEdgeEdgeOutputFormat
34    extends GoraEdgeOutputFormat<LongWritable, DoubleWritable,
35    FloatWritable> {
36  
37    /**
38     * Default constructor
39     */
40    public GoraGEdgeEdgeOutputFormat() {
41    }
42  
43    @Override
44    public GoraEdgeWriter createEdgeWriter(
45        TaskAttemptContext context) throws IOException, InterruptedException {
46      return new GoraGEdgeEdgeWriter();
47    }
48  
49    /**
50     * Gora edge writer.
51     */
52    protected class GoraGEdgeEdgeWriter
53      extends GoraEdgeWriter {
54  
55      @Override
56      protected Persistent getGoraEdge(LongWritable srcId,
57          DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) {
58        GEdgeResult tmpGEdge = new GEdgeResult();
59        tmpGEdge.setEdgeId(srcId.toString());
60        tmpGEdge.setEdgeWeight(edge.getValue().get());
61        tmpGEdge.setVertexOutId(edge.getTargetVertexId().toString());
62        getLogger().debug("GoraObject created: " + tmpGEdge.toString());
63        return tmpGEdge;
64      }
65  
66      @Override
67      protected Object getGoraKey(LongWritable srcId,
68          DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) {
69        String goraKey = String.valueOf(
70            edge.getTargetVertexId().get() + edge.getValue().get());
71        return goraKey;
72      }
73  
74    }
75  }