forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-11646] WholeTextFileRDD should return Text rather than String
If it returns Text, we can reuse this in Spark SQL to provide a WholeTextFile data source and directly convert the Text into UTF8String without extra string decoding and encoding. Author: Reynold Xin <[email protected]> Closes apache#9622 from rxin/SPARK-11646.
- Loading branch information
Showing
5 changed files
with
69 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/main/scala/org/apache/spark/rdd/WholeTextFileRDD.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.rdd | ||
|
||
import org.apache.hadoop.conf.{Configurable, Configuration} | ||
import org.apache.hadoop.io.{Text, Writable} | ||
import org.apache.hadoop.mapreduce.InputSplit | ||
|
||
import org.apache.spark.{Partition, SparkContext} | ||
import org.apache.spark.input.WholeTextFileInputFormat | ||
|
||
/** | ||
* An RDD that reads a bunch of text files in, and each text file becomes one record. | ||
*/ | ||
private[spark] class WholeTextFileRDD( | ||
sc : SparkContext, | ||
inputFormatClass: Class[_ <: WholeTextFileInputFormat], | ||
keyClass: Class[Text], | ||
valueClass: Class[Text], | ||
conf: Configuration, | ||
minPartitions: Int) | ||
extends NewHadoopRDD[Text, Text](sc, inputFormatClass, keyClass, valueClass, conf) { | ||
|
||
override def getPartitions: Array[Partition] = { | ||
val inputFormat = inputFormatClass.newInstance | ||
val conf = getConf | ||
inputFormat match { | ||
case configurable: Configurable => | ||
configurable.setConf(conf) | ||
case _ => | ||
} | ||
val jobContext = newJobContext(conf, jobId) | ||
inputFormat.setMinPartitions(jobContext, minPartitions) | ||
val rawSplits = inputFormat.getSplits(jobContext).toArray | ||
val result = new Array[Partition](rawSplits.size) | ||
for (i <- 0 until rawSplits.size) { | ||
result(i) = new NewHadoopPartition(id, i, rawSplits(i).asInstanceOf[InputSplit with Writable]) | ||
} | ||
result | ||
} | ||
} |