Skip to content

Commit 95de467

Browse files
rdbluecloud-fan
authored andcommitted
[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 <[email protected]> Closes #15062 from rdblue/SPARK-17424-fix-unsound-reflect-substitution. (cherry picked from commit b236933) Signed-off-by: Wenchen Fan <[email protected]>
1 parent 6e89d57 commit 95de467

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,16 @@ trait ScalaReflection {
814814
def getConstructorParameters(tpe: Type): Seq[(String, Type)] = {
815815
val formalTypeArgs = tpe.typeSymbol.asClass.typeParams
816816
val TypeRef(_, _, actualTypeArgs) = tpe
817-
constructParams(tpe).map { p =>
818-
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
817+
val params = constructParams(tpe)
818+
// if there are type variables to fill in, do the substitution (SomeClass[T] -> SomeClass[Int])
819+
if (actualTypeArgs.nonEmpty) {
820+
params.map { p =>
821+
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
822+
}
823+
} else {
824+
params.map { p =>
825+
p.name.toString -> p.typeSignature
826+
}
819827
}
820828
}
821829

0 commit comments

Comments
 (0)