diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala index 1986e8d51f4ce..72a60f0cb5c5f 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala @@ -486,7 +486,7 @@ case class NewInstance( ev.isNull = resultIsNull val constructorCall = outer.map { gen => - s"${gen.value}.new ${cls.getSimpleName}($argString)" + s"${gen.value}.new ${Utils.getSimpleName(cls)}($argString)" }.getOrElse { s"new $className($argString)" } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala index 1b02fa58552d0..efce0097c12b0 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala @@ -203,6 +203,36 @@ class ExpressionEncoderSuite extends CodegenInterpretedPlanTest with AnalysisTes encodeDecodeTest(Array(Option(InnerClass(1))), "array of optional inner class") + // NOTE: branch-2.4 does not have the interpreted implementation of SafeProjection, so + // it does not fall back into the interpreted mode if the compilation fails. + // Therefore, the test in this PR just checks that the compilation error happens + // instead of checking that the interpreted mode works well. + private def checkCompilationError[T : ExpressionEncoder]( + input: T, + testName: String): Unit = { + testAndVerifyNotLeakingReflectionObjects(s"compilation error: $testName: $input") { + val encoder = implicitly[ExpressionEncoder[T]] + val row = encoder.toRow(input) + val boundEncoder = encoder.resolveAndBind() + val errMsg = intercept[RuntimeException] { + boundEncoder.fromRow(row) + }.getCause.getMessage + assert(errMsg.contains("failed to compile: ")) + } + } + + // holder class to trigger Class.getSimpleName issue + object MalformedClassObject extends Serializable { + case class MalformedNameExample(x: Int) + } + + { + OuterScopes.addOuterScope(MalformedClassObject) + checkCompilationError( + MalformedClassObject.MalformedNameExample(42), + "nested Scala class") + } + productTest(PrimitiveData(1, 1, 1, 1, 1, 1, true)) productTest(