diff --git a/common/utils/src/main/resources/error/error-classes.json b/common/utils/src/main/resources/error/error-classes.json index 7350d0331c401..812c410155a59 100644 --- a/common/utils/src/main/resources/error/error-classes.json +++ b/common/utils/src/main/resources/error/error-classes.json @@ -3015,6 +3015,12 @@ ], "sqlState" : "4274K" }, + "UNEXPECTED_SERIALIZER_FOR_CLASS" : { + "message" : [ + "Class has unexpected serializer: ." + ], + "sqlState" : "42846" + }, "UNKNOWN_PROTOBUF_MESSAGE_TYPE" : { "message" : [ "Attempting to treat as a Message, but it was ." @@ -5715,11 +5721,6 @@ "." ] }, - "_LEGACY_ERROR_TEMP_2153" : { - "message" : [ - "class has unexpected serializer: ." - ] - }, "_LEGACY_ERROR_TEMP_2154" : { "message" : [ "Failed to get outer pointer for ." diff --git a/docs/sql-error-conditions.md b/docs/sql-error-conditions.md index 7890478005494..d3aabef456e50 100644 --- a/docs/sql-error-conditions.md +++ b/docs/sql-error-conditions.md @@ -1941,6 +1941,12 @@ Parameter `` of function `` requires the `` because it contains positional argument(s) following the named argument assigned to ``; please rearrange them so the positional arguments come first and then retry the query again. +### UNEXPECTED_SERIALIZER_FOR_CLASS + +[SQLSTATE: 42846](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation) + +Class has unexpected serializer: . + ### UNKNOWN_PROTOBUF_MESSAGE_TYPE [SQLSTATE: 42K0G](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala index 8d7819de052f1..8d328324589a0 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala @@ -1362,7 +1362,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE def classHasUnexpectedSerializerError( clsName: String, objSerializer: Expression): SparkRuntimeException = { new SparkRuntimeException( - errorClass = "_LEGACY_ERROR_TEMP_2153", + errorClass = "UNEXPECTED_SERIALIZER_FOR_CLASS", messageParameters = Map( "clsName" -> clsName, "objSerializer" -> objSerializer.toString())) 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 9d2051b01d62e..f964ed5560145 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 @@ -25,11 +25,11 @@ import scala.collection.mutable.ArrayBuffer import scala.reflect.runtime.universe.TypeTag import org.apache.spark.{SPARK_DOC_ROOT, SparkArithmeticException, SparkRuntimeException, SparkUnsupportedOperationException} -import org.apache.spark.sql.{Encoder, Encoders} +import org.apache.spark.sql.{Encoder, Encoders, Row} import org.apache.spark.sql.catalyst.{FooClassWithEnum, FooEnum, OptionalData, PrimitiveData, ScroogeLikeExample} import org.apache.spark.sql.catalyst.analysis.AnalysisTest import org.apache.spark.sql.catalyst.dsl.plans._ -import org.apache.spark.sql.catalyst.expressions.AttributeReference +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, NaNvl} import org.apache.spark.sql.catalyst.plans.CodegenInterpretedPlanTest import org.apache.spark.sql.catalyst.plans.logical.LocalRelation import org.apache.spark.sql.catalyst.types.DataTypeUtils.toAttributes @@ -37,7 +37,7 @@ import org.apache.spark.sql.catalyst.util.ArrayData import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.types._ import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String} -import org.apache.spark.util.ClosureCleaner +import org.apache.spark.util.{ClosureCleaner, Utils} case class RepeatedStruct(s: Seq[PrimitiveData]) @@ -576,6 +576,25 @@ class ExpressionEncoderSuite extends CodegenInterpretedPlanTest with AnalysisTes assert(e.getMessage.contains("tuple with more than 22 elements are not supported")) } + test("throw exception for unexpected serializer") { + val schema = new StructType() + .add("key", StringType) + .add("value", BinaryType) + + val encoder = ExpressionEncoder(schema, lenient = true) + val unexpectedSerializer = NaNvl(encoder.objSerializer, encoder.objSerializer) + val exception = intercept[org.apache.spark.SparkRuntimeException] { + new ExpressionEncoder[Row](unexpectedSerializer, encoder.objDeserializer, encoder.clsTag) + } + checkError( + exception = exception, + errorClass = "UNEXPECTED_SERIALIZER_FOR_CLASS", + parameters = Map( + "clsName" -> Utils.getSimpleName(encoder.clsTag.runtimeClass), + "objSerializer" -> unexpectedSerializer.toString()) + ) + } + encodeDecodeTest((1, FooEnum.E1), "Tuple with Int and scala Enum") encodeDecodeTest((null, FooEnum.E1, FooEnum.E2), "Tuple with Null and scala Enum") encodeDecodeTest(Seq(FooEnum.E1, null), "Seq with scala Enum")