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

    https://github.com/apache/spark/pull/1658#discussion_r17707338
  
    --- Diff: core/src/main/scala/org/apache/spark/input/RawFileInput.scala ---
    @@ -0,0 +1,221 @@
    +/*
    + * 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 scala.collection.JavaConversions._
    +import com.google.common.io.{ByteStreams, Closeables}
    +import org.apache.hadoop.mapreduce.InputSplit
    +import org.apache.hadoop.mapreduce.lib.input.CombineFileSplit
    +import org.apache.hadoop.mapreduce.RecordReader
    +import org.apache.hadoop.mapreduce.TaskAttemptContext
    +import org.apache.hadoop.fs.{FSDataInputStream, Path}
    +import org.apache.hadoop.mapreduce.lib.input.CombineFileInputFormat
    +import org.apache.hadoop.mapreduce.JobContext
    +import org.apache.hadoop.mapreduce.lib.input.CombineFileRecordReader
    +import java.io.DataInputStream
    +
    +
    +/**
    + *  A general format for reading whole files in as streams, byte arrays,
    + *  or other functions to be added
    + */
    +abstract class StreamFileInputFormat[T]
    +  extends CombineFileInputFormat[String,T]  {
    +  override protected def isSplitable(context: JobContext, file: Path): 
Boolean = false
    +  /**
    +   * Allow minPartitions set by end-user in order to keep compatibility 
with old Hadoop API.
    +   */
    +  def setMaxSplitSize(context: JobContext, minPartitions: Int) {
    +    val files = listStatus(context)
    +    val totalLen = files.map { file =>
    +      if (file.isDir) 0L else file.getLen
    +    }.sum
    +
    +    val maxSplitSize = Math.ceil(totalLen*1.0/files.length).toLong
    +    super.setMaxSplitSize(maxSplitSize)
    +  }
    +
    +  def createRecordReader(split: InputSplit, taContext: TaskAttemptContext):
    +  RecordReader[String,T]
    +
    +}
    +
    +/**
    + * A class that allows DataStreams to be serialized and moved around by 
not creating them
    + * until they need to be read
    + */
    +class PortableDataStream(split: CombineFileSplit, context: 
TaskAttemptContext, index: Integer)
    +  extends Serializable {
    +
    +  private var fileIn: FSDataInputStream = 
null.asInstanceOf[FSDataInputStream]
    +  private var isOpen = false
    +  /**
    +   * Calculate the path name independently of opening the file
    +   */
    +  private lazy val path = {
    +    val pathp = split.getPath(index)
    +    pathp.toString
    +  }
    +
    +  /**
    +   * create a new DataInputStream from the split and context
    +   */
    +  def open(): FSDataInputStream = {
    --- End diff --
    
    Instead of returning this Hadoop data type, can we return a 
java.io.DataInputStream? It's easier to maintain in the future.


---
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