From 6373f19f537f69c6460b2e4097f19903c01a608f Mon Sep 17 00:00:00 2001 From: dengziming Date: Tue, 10 Oct 2023 15:36:18 +0300 Subject: [PATCH] [SPARK-45213][SQL] Assign name to the error _LEGACY_ERROR_TEMP_2151 ### What changes were proposed in this pull request? Assign the name `EXPRESSION_DECODING_FAILED` to the legacy error class `_LEGACY_ERROR_TEMP_2151`. ### Why are the changes needed? To assign proper name as a part of activity in SPARK-37935. ### Does this PR introduce _any_ user-facing change? Yes, the error message will include the error class name ### How was this patch tested? An existing unit test to produce the error from user code. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #43029 from dengziming/SPARK-45213. Authored-by: dengziming Signed-off-by: Max Gekk --- .../utils/src/main/resources/error/error-classes.json | 11 +++++------ docs/sql-error-conditions.md | 6 ++++++ .../spark/sql/errors/QueryExecutionErrors.scala | 3 +-- .../catalyst/encoders/EncoderResolutionSuite.scala | 2 +- .../scala/org/apache/spark/sql/DatasetSuite.scala | 5 ++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/common/utils/src/main/resources/error/error-classes.json b/common/utils/src/main/resources/error/error-classes.json index 690d1ae1a14bd..1239793b3f9f9 100644 --- a/common/utils/src/main/resources/error/error-classes.json +++ b/common/utils/src/main/resources/error/error-classes.json @@ -921,6 +921,11 @@ } } }, + "EXPRESSION_DECODING_FAILED" : { + "message" : [ + "Failed to decode a row to a value of the expressions: ." + ] + }, "EXPRESSION_TYPE_IS_NOT_ORDERABLE" : { "message" : [ "Column expression cannot be sorted because its type is not orderable." @@ -5524,12 +5529,6 @@ "Due to Scala's limited support of tuple, tuple with more than 22 elements are not supported." ] }, - "_LEGACY_ERROR_TEMP_2151" : { - "message" : [ - "Error while decoding: ", - "." - ] - }, "_LEGACY_ERROR_TEMP_2152" : { "message" : [ "Error while encoding: ", diff --git a/docs/sql-error-conditions.md b/docs/sql-error-conditions.md index fda10eceb97a3..b4ee7358b5283 100644 --- a/docs/sql-error-conditions.md +++ b/docs/sql-error-conditions.md @@ -551,6 +551,12 @@ The table `` does not support ``. For more details see [EXPECT_VIEW_NOT_TABLE](sql-error-conditions-expect-view-not-table-error-class.html) +### EXPRESSION_DECODING_FAILED + +SQLSTATE: none assigned + +Failed to decode a row to a value of the expressions: ``. + ### EXPRESSION_TYPE_IS_NOT_ORDERABLE SQLSTATE: none assigned 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 bd4d7a3be7fb3..5396ae5ff7036 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 @@ -1342,9 +1342,8 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE def expressionDecodingError(e: Exception, expressions: Seq[Expression]): SparkRuntimeException = { new SparkRuntimeException( - errorClass = "_LEGACY_ERROR_TEMP_2151", + errorClass = "EXPRESSION_DECODING_FAILED", messageParameters = Map( - "e" -> e.toString(), "expressions" -> expressions.map( _.simpleString(SQLConf.get.maxToStringFields)).mkString("\n")), cause = e) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/EncoderResolutionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/EncoderResolutionSuite.scala index f4106e65e7c34..7f54987ee7ef8 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/EncoderResolutionSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/EncoderResolutionSuite.scala @@ -172,7 +172,7 @@ class EncoderResolutionSuite extends PlanTest { val e = intercept[RuntimeException] { fromRow(InternalRow(new GenericArrayData(Array(1, null)))) } - assert(e.getMessage.contains("Null value appeared in non-nullable field")) + assert(e.getCause.getMessage.contains("Null value appeared in non-nullable field")) } test("the real number of fields doesn't match encoder schema: tuple encoder") { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala index ca06e0f2bf2c9..2579b52bf72b0 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala @@ -1220,7 +1220,7 @@ class DatasetSuite extends QueryTest val message = intercept[RuntimeException] { buildDataset(Row(Row("hello", null))).collect() - }.getMessage + }.getCause.getMessage assert(message.contains("Null value appeared in non-nullable field")) } @@ -2592,9 +2592,8 @@ class DatasetSuite extends QueryTest // Expression decoding error checkError( exception = exception, - errorClass = "_LEGACY_ERROR_TEMP_2151", + errorClass = "EXPRESSION_DECODING_FAILED", parameters = Map( - "e" -> exception.getCause.toString(), "expressions" -> expressions.map( _.simpleString(SQLConf.get.maxToStringFields)).mkString("\n")) )