Coverage Report - org.apache.giraph.lib.AdjacencyListTextVertexOutputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
AdjacencyListTextVertexOutputFormat
0%
0/3
N/A
1.667
AdjacencyListTextVertexOutputFormat$AdjacencyListVertexWriter
0%
0/12
0%
0/4
1.667
 
 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.BasicVertex;
 21  
 import org.apache.giraph.graph.VertexWriter;
 22  
 import org.apache.hadoop.io.Text;
 23  
 import org.apache.hadoop.io.Writable;
 24  
 import org.apache.hadoop.io.WritableComparable;
 25  
 import org.apache.hadoop.mapreduce.RecordWriter;
 26  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 27  
 
 28  
 import java.io.IOException;
 29  
 
 30  
 /**
 31  
  * OutputFormat to write out the graph nodes as text, value-separated (by
 32  
  * tabs, by default).  With the default delimiter, a vertex is written out as:
 33  
  *
 34  
  * <VertexId><tab><Vertex Value><tab>[<EdgeId><tab><EdgeValue>]+
 35  
  *
 36  
  * @param <I> Vertex index value
 37  
  * @param <V> Vertex value
 38  
  * @param <E> Edge value
 39  
  */
 40  
 @SuppressWarnings("rawtypes")
 41  0
 public class AdjacencyListTextVertexOutputFormat<I extends WritableComparable,
 42  
     V extends Writable, E extends Writable>
 43  
     extends TextVertexOutputFormat<I, V, E> {
 44  
 
 45  
   /**
 46  
    * Vertex writer associated wtih {@link AdjacencyListTextVertexOutputFormat}.
 47  
    *
 48  
    * @param <I> Vertex id
 49  
    * @param <V> Vertex data
 50  
    * @param <E> Edge data
 51  
    */
 52  0
   static class AdjacencyListVertexWriter<I extends WritableComparable, V extends
 53  
       Writable, E extends Writable> extends TextVertexWriter<I, V, E> {
 54  
     /** Split delimiter */
 55  
     public static final String LINE_TOKENIZE_VALUE = "output.delimiter";
 56  
     /** Default split delimiter */
 57  
     public static final String LINE_TOKENIZE_VALUE_DEFAULT = "\t";
 58  
     /** Cached split delimeter */
 59  
     private String delimiter;
 60  
 
 61  
     /**
 62  
      * Constructor with writer.
 63  
      *
 64  
      * @param recordWriter Record writer used for writing.
 65  
      */
 66  
     public AdjacencyListVertexWriter(RecordWriter<Text, Text> recordWriter) {
 67  0
       super(recordWriter);
 68  0
     }
 69  
 
 70  
     @Override
 71  
     public void writeVertex(BasicVertex<I, V, E, ?> vertex) throws IOException,
 72  
     InterruptedException {
 73  0
       if (delimiter == null) {
 74  0
         delimiter = getContext().getConfiguration()
 75  
             .get(LINE_TOKENIZE_VALUE, LINE_TOKENIZE_VALUE_DEFAULT);
 76  
       }
 77  
 
 78  0
       StringBuffer sb = new StringBuffer(vertex.getVertexId().toString());
 79  0
       sb.append(delimiter);
 80  0
       sb.append(vertex.getVertexValue().toString());
 81  
 
 82  0
       for (I edge : vertex) {
 83  0
         sb.append(delimiter).append(edge);
 84  0
         sb.append(delimiter).append(vertex.getEdgeValue(edge));
 85  
       }
 86  
 
 87  0
       getRecordWriter().write(new Text(sb.toString()), null);
 88  0
     }
 89  
   }
 90  
 
 91  
   @Override
 92  
   public VertexWriter<I, V, E> createVertexWriter(TaskAttemptContext context)
 93  
     throws IOException, InterruptedException {
 94  0
     return new AdjacencyListVertexWriter<I, V, E>
 95  
     (textOutputFormat.getRecordWriter(context));
 96  
   }
 97  
 }