From ede05fa500feb02be23f89f37e8b29265ddfc5cc Mon Sep 17 00:00:00 2001 From: Haejoon Lee Date: Wed, 13 Nov 2024 09:18:06 +0100 Subject: [PATCH] [SPARK-50248][SQL] Assign appropriate error condition for `_LEGACY_ERROR_TEMP_2058`: `INVALID_PARTITION_VALUE` ### What changes were proposed in this pull request? This PR proposes to Integrate `_LEGACY_ERROR_TEMP_2058 ` into `INVALID_PARTITION_VALUE ` ### Why are the changes needed? To improve the error message by assigning proper error condition and SQLSTATE ### Does this PR introduce _any_ user-facing change? No, only user-facing error message improved ### How was this patch tested? Updated the existing tests ### Was this patch authored or co-authored using generative AI tooling? No Closes #48778 from itholic/LEGACY_2058. Authored-by: Haejoon Lee Signed-off-by: Max Gekk --- .../src/main/resources/error/error-conditions.json | 11 ++++++----- .../spark/sql/errors/QueryExecutionErrors.scala | 8 ++++---- .../sql/execution/datasources/FileIndexSuite.scala | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/utils/src/main/resources/error/error-conditions.json b/common/utils/src/main/resources/error/error-conditions.json index b3c92a9f2b9d1..553d085f88627 100644 --- a/common/utils/src/main/resources/error/error-conditions.json +++ b/common/utils/src/main/resources/error/error-conditions.json @@ -2950,6 +2950,12 @@ }, "sqlState" : "42601" }, + "INVALID_PARTITION_VALUE" : { + "message" : [ + "Failed to cast value to data type for partition column . Ensure the value matches the expected data type for this partition column." + ], + "sqlState" : "42846" + }, "INVALID_PROPERTY_KEY" : { "message" : [ " is an invalid property key, please use quotes, e.g. SET =." @@ -7026,11 +7032,6 @@ "Unable to clear partition directory prior to writing to it." ] }, - "_LEGACY_ERROR_TEMP_2058" : { - "message" : [ - "Failed to cast value `` to `` for partition column ``." - ] - }, "_LEGACY_ERROR_TEMP_2059" : { "message" : [ "End of stream." 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 0aa21a4d79c78..0e3f37d8d6fb5 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 @@ -795,11 +795,11 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE def failedToCastValueToDataTypeForPartitionColumnError( value: String, dataType: DataType, columnName: String): SparkRuntimeException = { new SparkRuntimeException( - errorClass = "_LEGACY_ERROR_TEMP_2058", + errorClass = "INVALID_PARTITION_VALUE", messageParameters = Map( - "value" -> value, - "dataType" -> dataType.toString(), - "columnName" -> columnName)) + "value" -> toSQLValue(value), + "dataType" -> toSQLType(dataType), + "columnName" -> toSQLId(columnName))) } def endOfStreamError(): Throwable = { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala index e9f78f9f598e1..33b4cc1d2e7f2 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala @@ -137,8 +137,8 @@ class FileIndexSuite extends SharedSparkSession { exception = intercept[SparkRuntimeException] { fileIndex.partitionSpec() }, - condition = "_LEGACY_ERROR_TEMP_2058", - parameters = Map("value" -> "foo", "dataType" -> "IntegerType", "columnName" -> "a") + condition = "INVALID_PARTITION_VALUE", + parameters = Map("value" -> "'foo'", "dataType" -> "\"INT\"", "columnName" -> "`a`") ) }