Coverage Report - org.apache.giraph.io.formats.SequenceFileVertexInputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
SequenceFileVertexInputFormat
0%
0/6
N/A
1
SequenceFileVertexInputFormat$SequenceFileVertexReader
0%
0/10
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  
 package org.apache.giraph.io.formats;
 19  
 
 20  
 import org.apache.giraph.graph.Vertex;
 21  
 import org.apache.giraph.io.VertexInputFormat;
 22  
 import org.apache.giraph.io.VertexReader;
 23  
 import org.apache.hadoop.conf.Configuration;
 24  
 import org.apache.hadoop.io.Writable;
 25  
 import org.apache.hadoop.io.WritableComparable;
 26  
 import org.apache.hadoop.mapreduce.InputSplit;
 27  
 import org.apache.hadoop.mapreduce.JobContext;
 28  
 import org.apache.hadoop.mapreduce.RecordReader;
 29  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 30  
 import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
 31  
 
 32  
 import java.io.IOException;
 33  
 import java.util.List;
 34  
 
 35  
 /**
 36  
  * Sequence file vertex input format based on {@link SequenceFileInputFormat}.
 37  
  *
 38  
  * @param <I> Vertex id
 39  
  * @param <V> Vertex data
 40  
  * @param <E> Edge data
 41  
  * @param <X> Value type
 42  
  */
 43  
 @SuppressWarnings("rawtypes")
 44  0
 public class SequenceFileVertexInputFormat<I extends WritableComparable,
 45  
     V extends Writable, E extends Writable, X extends Vertex<I, V, E>>
 46  
     extends VertexInputFormat<I, V, E> {
 47  
   /** Internal input format */
 48  0
   protected SequenceFileInputFormat<I, X> sequenceFileInputFormat =
 49  
     new SequenceFileInputFormat<I, X>();
 50  
 
 51  0
   @Override public void checkInputSpecs(Configuration conf) { }
 52  
 
 53  
   @Override
 54  
   public List<InputSplit> getSplits(JobContext context, int minSplitCountHint)
 55  
     throws IOException, InterruptedException {
 56  0
     return sequenceFileInputFormat.getSplits(context);
 57  
   }
 58  
 
 59  
   @Override
 60  
   public VertexReader<I, V, E> createVertexReader(InputSplit split,
 61  
       TaskAttemptContext context) throws IOException {
 62  0
     return new SequenceFileVertexReader<I, V, E, X>(
 63  0
         sequenceFileInputFormat.createRecordReader(split, context));
 64  
   }
 65  
 
 66  
   /**
 67  
    * Vertex reader used with {@link SequenceFileVertexInputFormat}.
 68  
    *
 69  
    * @param <I> Vertex id
 70  
    * @param <V> Vertex data
 71  
    * @param <E> Edge data
 72  
    * @param <X> Value type
 73  
    */
 74  
   public static class SequenceFileVertexReader<I extends WritableComparable,
 75  
       V extends Writable, E extends Writable, X extends Vertex<I, V, E>>
 76  
       extends VertexReader<I, V, E> {
 77  
     /** Internal record reader from {@link SequenceFileInputFormat} */
 78  
     private final RecordReader<I, X> recordReader;
 79  
 
 80  
     /**
 81  
      * Constructor with record reader.
 82  
      *
 83  
      * @param recordReader Reader from {@link SequenceFileInputFormat}.
 84  
      */
 85  0
     public SequenceFileVertexReader(RecordReader<I, X> recordReader) {
 86  0
       this.recordReader = recordReader;
 87  0
     }
 88  
 
 89  
     @Override public void initialize(InputSplit inputSplit,
 90  
         TaskAttemptContext context) throws IOException, InterruptedException {
 91  0
       recordReader.initialize(inputSplit, context);
 92  0
     }
 93  
 
 94  
     @Override public boolean nextVertex() throws IOException,
 95  
         InterruptedException {
 96  0
       return recordReader.nextKeyValue();
 97  
     }
 98  
 
 99  
     @Override public Vertex<I, V, E> getCurrentVertex()
 100  
       throws IOException, InterruptedException {
 101  0
       return recordReader.getCurrentValue();
 102  
     }
 103  
 
 104  
 
 105  
     @Override public void close() throws IOException {
 106  0
       recordReader.close();
 107  0
     }
 108  
 
 109  
     @Override public float getProgress() throws IOException,
 110  
         InterruptedException {
 111  0
       return recordReader.getProgress();
 112  
     }
 113  
   }
 114  
 }