Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1658#discussion_r18613166
  
    --- Diff: 
core/src/main/scala/org/apache/spark/input/FixedLengthBinaryRecordReader.scala 
---
    @@ -0,0 +1,147 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.input
    +
    +import java.io.IOException
    +
    +import org.apache.hadoop.fs.FSDataInputStream
    +import org.apache.hadoop.io.compress.CompressionCodecFactory
    +import org.apache.hadoop.io.{BytesWritable, LongWritable}
    +import org.apache.hadoop.mapreduce.{InputSplit, RecordReader, 
TaskAttemptContext}
    +import org.apache.hadoop.mapreduce.lib.input.FileSplit
    +
    +/**
    + *
    + * FixedLengthBinaryRecordReader is returned by 
FixedLengthBinaryInputFormat.
    + * It uses the record length set in FixedLengthBinaryInputFormat to
    + * read one record at a time from the given InputSplit.
    + *
    + * Each call to nextKeyValue() updates the LongWritable KEY and 
BytesWritable VALUE.
    + *
    + * KEY = record index (Long)
    + * VALUE = the record itself (BytesWritable)
    + *
    + */
    +private[spark] class FixedLengthBinaryRecordReader
    +  extends RecordReader[LongWritable, BytesWritable] {
    +
    +  override def close() {
    +    if (fileInputStream != null) {
    +      fileInputStream.close()
    +    }
    +  }
    +
    +  override def getCurrentKey: LongWritable = {
    +    recordKey
    +  }
    +
    +  override def getCurrentValue: BytesWritable = {
    +    recordValue
    +  }
    +
    +  override def getProgress: Float = {
    +    splitStart match {
    +      case x if x == splitEnd => 0.0.toFloat
    +      case _ => Math.min(
    +        ((currentPosition - splitStart) / (splitEnd - 
splitStart)).toFloat, 1.0
    +      ).toFloat
    +    }
    +  }
    +
    +  override def initialize(inputSplit: InputSplit, context: 
TaskAttemptContext) {
    +
    +    // the file input
    +    val fileSplit = inputSplit.asInstanceOf[FileSplit]
    +
    +    // the byte position this fileSplit starts at
    +    splitStart = fileSplit.getStart
    +
    +    // splitEnd byte marker that the fileSplit ends at
    +    splitEnd = splitStart + fileSplit.getLength
    +
    +    // the actual file we will be reading from
    +    val file = fileSplit.getPath
    +
    +    // job configuration
    +    val job = context.getConfiguration
    +
    +    // check compression
    +    val codec = new CompressionCodecFactory(job).getCodec(file)
    +    if (codec != null) {
    +      throw new IOException("FixedLengthRecordReader does not support 
reading compressed files")
    +    }
    +
    +    // get the record length
    +    recordLength = FixedLengthBinaryInputFormat.getRecordLength(context)
    +
    +    // get the filesystem
    +    val fs = file.getFileSystem(job)
    +
    +    // open the File
    +    fileInputStream = fs.open(file)
    +
    +    // seek to the splitStart position
    +    fileInputStream.seek(splitStart)
    +
    +    // set our current position
    +    currentPosition = splitStart
    +
    --- End diff --
    
    Avoid blank lines at end of methods


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to