Coverage Report - org.apache.giraph.examples.VertexWithComponentTextOutputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
VertexWithComponentTextOutputFormat
0%
0/4
N/A
1
VertexWithComponentTextOutputFormat$VertexWithComponentWriter
0%
0/8
N/A
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  
 
 19  
 package org.apache.giraph.examples;
 20  
 
 21  
 import org.apache.giraph.graph.BasicVertex;
 22  
 import org.apache.giraph.graph.VertexWriter;
 23  
 import org.apache.giraph.lib.TextVertexOutputFormat;
 24  
 import org.apache.hadoop.io.IntWritable;
 25  
 import org.apache.hadoop.io.NullWritable;
 26  
 import org.apache.hadoop.io.Text;
 27  
 import org.apache.hadoop.mapreduce.RecordWriter;
 28  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 29  
 
 30  
 import java.io.IOException;
 31  
 
 32  
 /**
 33  
  * Text-based {@link org.apache.giraph.graph.VertexOutputFormat} for usage with
 34  
  * {@link ConnectedComponentsVertex}
 35  
  *
 36  
  * Each line consists of a vertex and its associated component (represented
 37  
  *  by the smallest vertex id in the component)
 38  
  */
 39  0
 public class VertexWithComponentTextOutputFormat extends
 40  
     TextVertexOutputFormat<IntWritable, IntWritable, NullWritable> {
 41  
   @Override
 42  
   public VertexWriter<IntWritable, IntWritable, NullWritable>
 43  
   createVertexWriter(TaskAttemptContext context)
 44  
     throws IOException, InterruptedException {
 45  0
     RecordWriter<Text, Text> recordWriter =
 46  
         textOutputFormat.getRecordWriter(context);
 47  0
     return new VertexWithComponentWriter(recordWriter);
 48  
   }
 49  
 
 50  
   /**
 51  
    * Vertex writer used with {@link VertexWithComponentTextOutputFormat}.
 52  
    */
 53  0
   public static class VertexWithComponentWriter extends
 54  
       TextVertexOutputFormat.TextVertexWriter<IntWritable, IntWritable,
 55  
       NullWritable> {
 56  
     /**
 57  
      * Constructor with record writer.
 58  
      *
 59  
      * @param writer Where the vertices will finally be written.
 60  
      */
 61  
     public VertexWithComponentWriter(RecordWriter<Text, Text> writer) {
 62  0
       super(writer);
 63  0
     }
 64  
 
 65  
     @Override
 66  
     public void writeVertex(BasicVertex<IntWritable, IntWritable,
 67  
         NullWritable, ?> vertex) throws IOException,
 68  
         InterruptedException {
 69  0
       StringBuilder output = new StringBuilder();
 70  0
       output.append(vertex.getVertexId().get());
 71  0
       output.append('\t');
 72  0
       output.append(vertex.getVertexValue().get());
 73  0
       getRecordWriter().write(new Text(output.toString()), null);
 74  0
     }
 75  
   }
 76  
 }