Coverage Report - org.apache.giraph.io.formats.AdjacencyListTextVertexOutputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
AdjacencyListTextVertexOutputFormat
0%
0/3
N/A
1.333
AdjacencyListTextVertexOutputFormat$AdjacencyListTextVertexWriter
0%
0/13
0%
0/2
1.333
 
 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.graph.Vertex;
 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.TaskAttemptContext;
 26  
 
 27  
 import java.io.IOException;
 28  
 
 29  
 /**
 30  
  * OutputFormat to write out the graph nodes as text, value-separated (by
 31  
  * tabs, by default).  With the default delimiter, a vertex is written out as:
 32  
  *
 33  
  * <VertexId><tab><Vertex Value><tab>
 34  
  * [<EdgeId><tab><EdgeValue>]+
 35  
  *
 36  
  * @param <I> Vertex index value
 37  
  * @param <V> Vertex value
 38  
  * @param <E> Edge value
 39  
  */
 40  0
 @SuppressWarnings("rawtypes")
 41  0
 public class AdjacencyListTextVertexOutputFormat<I extends WritableComparable,
 42  
     V extends Writable, E extends Writable>
 43  
     extends TextVertexOutputFormat<I, V, E> {
 44  
   /** Split delimiter */
 45  
   public static final String LINE_TOKENIZE_VALUE = "output.delimiter";
 46  
   /** Default split delimiter */
 47  
   public static final String LINE_TOKENIZE_VALUE_DEFAULT =
 48  
     AdjacencyListTextVertexInputFormat.LINE_TOKENIZE_VALUE_DEFAULT;
 49  
 
 50  
   @Override
 51  
   public AdjacencyListTextVertexWriter createVertexWriter(
 52  
       TaskAttemptContext context) {
 53  0
     return new AdjacencyListTextVertexWriter();
 54  
   }
 55  
 
 56  
   /**
 57  
    * Vertex writer associated with {@link AdjacencyListTextVertexOutputFormat}.
 58  
    */
 59  0
   protected class AdjacencyListTextVertexWriter extends
 60  
     TextVertexWriterToEachLine {
 61  
     /** Cached split delimeter */
 62  
     private String delimiter;
 63  
 
 64  
     @Override
 65  
     public void initialize(TaskAttemptContext context) throws IOException,
 66  
         InterruptedException {
 67  0
       super.initialize(context);
 68  0
       delimiter =
 69  0
           getConf().get(LINE_TOKENIZE_VALUE, LINE_TOKENIZE_VALUE_DEFAULT);
 70  0
     }
 71  
 
 72  
     @Override
 73  
     public Text convertVertexToLine(Vertex<I, V, E> vertex)
 74  
       throws IOException {
 75  0
       StringBuffer sb = new StringBuffer(vertex.getId().toString());
 76  0
       sb.append(delimiter);
 77  0
       sb.append(vertex.getValue());
 78  
 
 79  0
       for (Edge<I, E> edge : vertex.getEdges()) {
 80  0
         sb.append(delimiter).append(edge.getTargetVertexId());
 81  0
         sb.append(delimiter).append(edge.getValue());
 82  0
       }
 83  
 
 84  0
       return new Text(sb.toString());
 85  
     }
 86  
   }
 87  
 
 88  
 }