[SPARK-17424] Fix unsound substitution bug in ScalaReflection.
## What changes were proposed in this pull request? This method gets a type's primary constructor and fills in type parameters with concrete types. For example, `MapPartitions[T, U] -> MapPartitions[Int, String]`. This Substitution fails when the actual type args are empty because they are still unknown. Instead, when there are no resolved types to subsitute, this returns the original args with unresolved type parameters. ## How was this patch tested? This doesn't affect substitutions where the type args are determined. This fixes our case where the actual type args are empty and our job runs successfully. Author: Ryan Blue <blue@apache.org> Closes #15062 from rdblue/SPARK-17424-fix-unsound-reflect-substitution.
This commit is contained in:
parent
fc8a2b6ee6
commit
b236933907
|
@ -836,8 +836,16 @@ trait ScalaReflection {
|
|||
def getConstructorParameters(tpe: Type): Seq[(String, Type)] = {
|
||||
val formalTypeArgs = tpe.typeSymbol.asClass.typeParams
|
||||
val TypeRef(_, _, actualTypeArgs) = tpe
|
||||
constructParams(tpe).map { p =>
|
||||
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
|
||||
val params = constructParams(tpe)
|
||||
// if there are type variables to fill in, do the substitution (SomeClass[T] -> SomeClass[Int])
|
||||
if (actualTypeArgs.nonEmpty) {
|
||||
params.map { p =>
|
||||
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
|
||||
}
|
||||
} else {
|
||||
params.map { p =>
|
||||
p.name.toString -> p.typeSignature
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue