You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by yi...@apache.org on 2026/08/06 16:45:34 UTC

(spark) branch branch-4.x updated: [SPARK-58350][SQL] Assign a name to the error condition _LEGACY_ERROR_TEMP_1228

This is an automated email from the ASF dual-hosted git repository.

Yicong-Huang pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new 7fb8b0d4f825 [SPARK-58350][SQL] Assign a name to the error condition _LEGACY_ERROR_TEMP_1228
7fb8b0d4f825 is described below

commit 7fb8b0d4f825312917bd207c41e1d7c18dc11d28
Author: Xiao Li <li...@databricks.com>
AuthorDate: Thu Aug 6 16:44:48 2026 +0000

    [SPARK-58350][SQL] Assign a name to the error condition _LEGACY_ERROR_TEMP_1228
    
    ### What changes were proposed in this pull request?
    
    Assign the name `DECIMAL_SCALE_EXCEEDS_PRECISION` to the legacy error condition
    `_LEGACY_ERROR_TEMP_1228`. This error is raised by
    `DataTypeErrors.decimalCannotGreaterThanPrecisionError` when a `DecimalType` is
    constructed with scale greater than precision. The new condition is given SQLSTATE
    `22003` (matching the sibling `DECIMAL_PRECISION_EXCEEDS_MAX_PRECISION`); the message
    text and the `scale`/`precision` parameters are unchanged.
    
    ### Why are the changes needed?
    
    The error conditions [README](https://github.com/apache/spark/blob/master/common/utils/src/main/resources/error/README.md)
    disallows new `_LEGACY_ERROR_TEMP_*` entries and asks existing ones to be assigned
    proper names. This resolves one of them, under the umbrella
    [SPARK-37935](https://issues.apache.org/jira/browse/SPARK-37935).
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. The `_LEGACY_ERROR_TEMP_*` names are not part of the public API. The error
    condition name changes to `DECIMAL_SCALE_EXCEEDS_PRECISION` and now reports SQLSTATE
    `22003`; the rendered message ("Decimal scale (`<scale>`) cannot be greater than
    precision (`<precision>`).") is unchanged.
    
    ### How was this patch tested?
    
    Added a `checkError` test in `DataTypeSuite` that constructs `DecimalType(2, 3)` and
    asserts the `DECIMAL_SCALE_EXCEEDS_PRECISION` condition. `SparkThrowableSuite`
    validates error-file formatting/sorting and that non-legacy conditions carry a
    SQLSTATE.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Yes
    
    Closes #57538 from gatorsmile/SPARK-58350-decimal-scale-precision.
    
    Authored-by: Xiao Li <li...@databricks.com>
    Signed-off-by: Yicong-Huang <17...@users.noreply.github.com>
    (cherry picked from commit 06eb04c0eb50d6a113b692ffb01aeae4a58317bc)
    Signed-off-by: Yicong-Huang <17...@users.noreply.github.com>
---
 common/utils/src/main/resources/error/error-conditions.json   | 11 ++++++-----
 .../scala/org/apache/spark/sql/errors/DataTypeErrors.scala    |  2 +-
 .../test/scala/org/apache/spark/sql/types/DataTypeSuite.scala | 11 +++++++++++
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/common/utils/src/main/resources/error/error-conditions.json b/common/utils/src/main/resources/error/error-conditions.json
index 9ff51c66fc6b..867e2d9dae30 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -2286,6 +2286,12 @@
     ],
     "sqlState" : "22003"
   },
+  "DECIMAL_SCALE_EXCEEDS_PRECISION" : {
+    "message" : [
+      "Decimal scale (<scale>) cannot be greater than precision (<precision>)."
+    ],
+    "sqlState" : "22003"
+  },
   "DEFAULT_DATABASE_NOT_EXISTS" : {
     "message" : [
       "Default database <defaultDatabase> does not exist, please create it first or change default database to `<defaultDatabase>`."
@@ -10286,11 +10292,6 @@
       "The SQL config '<configName>' was removed in the version <version>. <comment>"
     ]
   },
-  "_LEGACY_ERROR_TEMP_1228" : {
-    "message" : [
-      "Decimal scale (<scale>) cannot be greater than precision (<precision>)."
-    ]
-  },
   "_LEGACY_ERROR_TEMP_1232" : {
     "message" : [
       "Partition spec is invalid. The spec (<specKeys>) must match the partition spec (<partitionColumnNames>) defined in table '<tableName>'."
diff --git a/sql/api/src/main/scala/org/apache/spark/sql/errors/DataTypeErrors.scala b/sql/api/src/main/scala/org/apache/spark/sql/errors/DataTypeErrors.scala
index 326d918f2486..f59470c1f1b3 100644
--- a/sql/api/src/main/scala/org/apache/spark/sql/errors/DataTypeErrors.scala
+++ b/sql/api/src/main/scala/org/apache/spark/sql/errors/DataTypeErrors.scala
@@ -139,7 +139,7 @@ private[sql] object DataTypeErrors extends DataTypeErrorsBase {
 
   def decimalCannotGreaterThanPrecisionError(scale: Int, precision: Int): Throwable = {
     new AnalysisException(
-      errorClass = "_LEGACY_ERROR_TEMP_1228",
+      errorClass = "DECIMAL_SCALE_EXCEEDS_PRECISION",
       messageParameters = Map("scale" -> scale.toString, "precision" -> precision.toString))
   }
 
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
index 6403e1509858..6aae5047395d 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
@@ -24,6 +24,7 @@ import org.json4s.jackson.JsonMethods
 
 import org.apache.spark.{SparkClassNotFoundException, SparkException, SparkFunSuite}
 import org.apache.spark.SparkIllegalArgumentException
+import org.apache.spark.sql.AnalysisException
 import org.apache.spark.sql.catalyst.analysis.{caseInsensitiveResolution, caseSensitiveResolution}
 import org.apache.spark.sql.catalyst.parser.{CatalystSqlParser, ParseException}
 import org.apache.spark.sql.catalyst.plans.SQLHelper
@@ -1734,4 +1735,14 @@ class DataTypeSuite extends SparkFunSuite with SQLHelper {
         s"${clazz.getSimpleName}: PhysicalDataType should recognize non-singleton instance")
     }
   }
+
+  test("SPARK-58350: DecimalType with scale greater than precision throws " +
+    "DECIMAL_SCALE_EXCEEDS_PRECISION") {
+    checkError(
+      exception = intercept[AnalysisException] {
+        DecimalType(2, 3)
+      },
+      condition = "DECIMAL_SCALE_EXCEEDS_PRECISION",
+      parameters = Map("scale" -> "3", "precision" -> "2"))
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org