Coverage Report - org.apache.giraph.io.formats.SrcIdDstIdEdgeValueTextOutputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
SrcIdDstIdEdgeValueTextOutputFormat
0%
0/3
N/A
1.333
SrcIdDstIdEdgeValueTextOutputFormat$SrcIdDstIdEdgeValueEdgeWriter
0%
0/18
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  
 
 19  
 package org.apache.giraph.io.formats;
 20  
 
 21  
 import java.io.IOException;
 22  
 
 23  
 import org.apache.giraph.edge.Edge;
 24  
 import org.apache.hadoop.io.Text;
 25  
 import org.apache.hadoop.io.Writable;
 26  
 import org.apache.hadoop.io.WritableComparable;
 27  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 28  
 
 29  
 import static org.apache.giraph.conf.GiraphConstants.GIRAPH_TEXT_OUTPUT_FORMAT_SEPARATOR;
 30  
 import static org.apache.giraph.conf.GiraphConstants.GIRAPH_TEXT_OUTPUT_FORMAT_REVERSE;
 31  
 
 32  
 /**
 33  
  * Write out Edge Value with Source and Destination ID, but not the vertex
 34  
  * value.
 35  
  * This is a demostration output format to show the possibility to separately
 36  
  * output edges from vertices.
 37  
  *
 38  
  * @param <I> Vertex index value
 39  
  * @param <V> Vertex value
 40  
  * @param <E> Edge value
 41  
  */
 42  0
 @SuppressWarnings("rawtypes")
 43  0
 public class SrcIdDstIdEdgeValueTextOutputFormat<I extends WritableComparable,
 44  
     V extends Writable, E extends Writable>
 45  
     extends TextEdgeOutputFormat<I, V, E> {
 46  
 
 47  
   @Override
 48  
   public TextEdgeWriter createEdgeWriter(TaskAttemptContext context) {
 49  0
     return new SrcIdDstIdEdgeValueEdgeWriter();
 50  
   }
 51  
 
 52  
   /**
 53  
    * Edge writer used with {@link SrcIdDstIdEdgeValueTextOutputFormat}.
 54  
    */
 55  0
   protected class SrcIdDstIdEdgeValueEdgeWriter<I extends WritableComparable,
 56  
     V extends Writable, E extends Writable>
 57  
     extends TextEdgeWriterToEachLine<I, V, E> {
 58  
 
 59  
     /** Saved delimiter */
 60  
     private String delimiter;
 61  
     /** Cached reserve option */
 62  
     private boolean reverseOutput;
 63  
 
 64  
     @Override
 65  
     public void initialize(TaskAttemptContext context)
 66  
       throws IOException, InterruptedException {
 67  0
       super.initialize(context);
 68  0
       delimiter = GIRAPH_TEXT_OUTPUT_FORMAT_SEPARATOR.get(getConf());
 69  0
       reverseOutput = GIRAPH_TEXT_OUTPUT_FORMAT_REVERSE.get(getConf());
 70  0
     }
 71  
 
 72  
     @Override
 73  
     protected Text convertEdgeToLine(I sourceId, V sourceValue, Edge<I, E> edge)
 74  
       throws IOException {
 75  0
       StringBuilder msg = new StringBuilder();
 76  0
       if (reverseOutput) {
 77  0
         msg.append(edge.getValue().toString());
 78  0
         msg.append(delimiter);
 79  0
         msg.append(edge.getTargetVertexId().toString());
 80  0
         msg.append(delimiter);
 81  0
         msg.append(sourceId.toString());
 82  
       } else {
 83  0
         msg.append(sourceId.toString());
 84  0
         msg.append(delimiter);
 85  0
         msg.append(edge.getTargetVertexId().toString());
 86  0
         msg.append(delimiter);
 87  0
         msg.append(edge.getValue().toString());
 88  
       }
 89  0
       return new Text(msg.toString());
 90  
     }
 91  
   }
 92  
 }