Skip to content

Commit

Permalink
cache the FileScanRDD constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Graves <tgraves@nvidia.com>
  • Loading branch information
tgravescs committed Sep 22, 2020
1 parent dfcd3cf commit 920bf18
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.nvidia.spark.rapids.shims.spark300emr

import java.lang.reflect.Constructor

import com.nvidia.spark.rapids._
import com.nvidia.spark.rapids.shims.spark300.Spark300Shims
import com.nvidia.spark.rapids.spark300emr.RapidsShuffleManager
Expand All @@ -27,6 +29,8 @@ import org.apache.spark.sql.execution.datasources.{FilePartition, FileScanRDD, P

class Spark300EMRShims extends Spark300Shims {

private var fileScanRddConstructor: Option[Constructor[_]] = None

override def getSparkShimVersion: ShimVersion = SparkShimServiceProvider.VERSION

override def getRapidsShuffleManagerClass: String = {
Expand All @@ -39,12 +43,16 @@ class Spark300EMRShims extends Spark300Shims {
readFunction: (PartitionedFile) => Iterator[InternalRow],
filePartitions: Seq[FilePartition]): RDD[InternalRow] = {

val tclass = classOf[org.apache.spark.sql.execution.datasources.FileScanRDD]
val constructors = tclass.getConstructors()
if (constructors.size > 1) {
throw new IllegalStateException(s"Only expected 1 constructor for FileScanRDD")
val constructor = fileScanRddConstructor.getOrElse {
val tclass = classOf[org.apache.spark.sql.execution.datasources.FileScanRDD]
val constructors = tclass.getConstructors()
if (constructors.size > 1) {
throw new IllegalStateException(s"Only expected 1 constructor for FileScanRDD")
}
val cnstr = constructors(0)
fileScanRddConstructor = Some(cnstr)
cnstr
}
val constructor = constructors(0)
val instance = if (constructor.getParameterCount() == 4) {
constructor.newInstance(sparkSession, readFunction, filePartitions, None)
} else if (constructor.getParameterCount() == 3) {
Expand Down

0 comments on commit 920bf18

Please sign in to comment.