You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "imarkowitz (via GitHub)" <gi...@apache.org> on 2025/09/05 23:43:42 UTC

[PR] [WIP] [SPARK-53507]Add breaking change info to errors [spark]

imarkowitz opened a new pull request, #52256:
URL: https://github.com/apache/spark/pull/52256

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   Adds breaking change metadata to error messages
   
   Each breaking change includes a migration message explaining how the user should update their code. It also can include a spark config value which can be used to mitigate the breaking change.
   
   The migration message is concatenated to the error message. In Scala, we also include the breaking change info in the structured error message, when the STANDARD error format is used.
   
   We also include breaking change info in pyspark errors.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   By tagging breaking changes with metadata and a spark config flag, we can build tools to automatically retry spark jobs with the breaking change disabled.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "imarkowitz (via GitHub)" <gi...@apache.org>.
imarkowitz commented on PR #52256:
URL: https://github.com/apache/spark/pull/52256#issuecomment-3304534215

   Test failures in `org.apache.spark.sql.kafka010.KafkaMicroBatchV1SourceWithConsumerSuite` and `org.apache.spark.sql.jdbc.v2.OracleIntegrationSuite` look unrelated


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #52256: [SPARK-53507][CONNECT] Add breaking change info to errors
URL: https://github.com/apache/spark/pull/52256


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "imarkowitz (via GitHub)" <gi...@apache.org>.
imarkowitz commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2350208948


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -46,24 +46,28 @@ class ErrorClassesJsonReader(jsonFileURLs: Seq[URL]) {
       case (key, value) => key -> value
     }
     val sub = new StringSubstitutor(sanitizedParameters)
-    val errorMessage = try {
-      sub.replace(ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(
-        messageTemplate, "\\$\\{$1\\}"))
-    } catch {
-      case i: IllegalArgumentException => throw SparkException.internalError(
-        s"Undefined error message parameter for error class: '$errorClass', " +
-          s"MessageTemplate: $messageTemplate, " +
-          s"Parameters: $messageParameters", i)
-    }
+    val errorMessage =
+      try {
+        sub.replace(
+          ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(messageTemplate, "\\$\\{$1\\}"))
+      } catch {
+        case i: IllegalArgumentException =>
+          throw SparkException.internalError(
+            s"Undefined error message parameter for error class: '$errorClass', " +
+              s"MessageTemplate: $messageTemplate, " +
+              s"Parameters: $messageParameters",
+            i)
+      }
     if (util.SparkEnvUtils.isTesting) {
-      val placeHoldersNum = ErrorClassesJsonReader.TEMPLATE_REGEX.findAllIn(messageTemplate).length
+      val placeHoldersNum =

Review Comment:
   Reverted



##########
common/utils/src/main/java/org/apache/spark/SparkThrowable.java:
##########
@@ -60,6 +61,11 @@ default boolean isInternalError() {
     return SparkThrowableHelper.isInternalError(this.getCondition());
   }
 
+  default Optional<BreakingChangeInfo> getBreakingChangeInfo() {

Review Comment:
   Done



##########
common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -37,15 +37,11 @@ private[spark] object SparkThrowableHelper {
     // of this ticket: https://issues.apache.org/jira/browse/SPARK-47429
     Seq(SparkClassUtils.getSparkClassLoader.getResource("error/error-conditions.json")))
 
-  def getMessage(
-      errorClass: String,
-      messageParameters: Map[String, String]): String = {
+  def getMessage(errorClass: String, messageParameters: Map[String, String]): String = {

Review Comment:
   Done. These were auto-generated from running `./dev/scalafmt` -- is there a better workflow for formatting these changes?



##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -143,39 +165,81 @@ private object ErrorClassesJsonReader {
 /**
  * Information associated with an error class.
  *
- * @param sqlState SQLSTATE associated with this class.
- * @param subClass SubClass associated with this class.
- * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
- *                The error message is constructed by concatenating the lines with newlines.
+ * @param sqlState
+ *   SQLSTATE associated with this class.
+ * @param subClass
+ *   SubClass associated with this class.
+ * @param message
+ *   Message format with optional placeholders (e.g. &lt;parm&gt;). The error message is
+ *   constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo
+ *   Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +

Review Comment:
   I think it makes sense to use a space



##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -46,24 +46,28 @@ class ErrorClassesJsonReader(jsonFileURLs: Seq[URL]) {
       case (key, value) => key -> value
     }
     val sub = new StringSubstitutor(sanitizedParameters)
-    val errorMessage = try {
-      sub.replace(ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(
-        messageTemplate, "\\$\\{$1\\}"))
-    } catch {
-      case i: IllegalArgumentException => throw SparkException.internalError(
-        s"Undefined error message parameter for error class: '$errorClass', " +
-          s"MessageTemplate: $messageTemplate, " +
-          s"Parameters: $messageParameters", i)
-    }
+    val errorMessage =

Review Comment:
   Reverted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2342951455


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -143,39 +165,81 @@ private object ErrorClassesJsonReader {
 /**
  * Information associated with an error class.
  *
- * @param sqlState SQLSTATE associated with this class.
- * @param subClass SubClass associated with this class.
- * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
- *                The error message is constructed by concatenating the lines with newlines.
+ * @param sqlState
+ *   SQLSTATE associated with this class.
+ * @param subClass
+ *   SubClass associated with this class.
+ * @param message
+ *   Message format with optional placeholders (e.g. &lt;parm&gt;). The error message is
+ *   constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo
+ *   Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +

Review Comment:
   nit: shall we add an `\n` between the main error message and the breaking change message?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "imarkowitz (via GitHub)" <gi...@apache.org>.
imarkowitz commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2353563921


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -143,39 +165,81 @@ private object ErrorClassesJsonReader {
 /**
  * Information associated with an error class.
  *
- * @param sqlState SQLSTATE associated with this class.
- * @param subClass SubClass associated with this class.
- * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
- *                The error message is constructed by concatenating the lines with newlines.
+ * @param sqlState
+ *   SQLSTATE associated with this class.
+ * @param subClass
+ *   SubClass associated with this class.
+ * @param message
+ *   Message format with optional placeholders (e.g. &lt;parm&gt;). The error message is
+ *   constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo
+ *   Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +

Review Comment:
   I based this code on the existing logic for joining the subclass message: https://github.com/apache/spark/blob/0fb89df2df10cbec394b3723373716d2ee1c1c33/common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala#L111
   
   That logic uses a space so I think it makes sense to match that for consistency.
   
   In the common case where the message is a single line, I think a newline is more confusing than a space.



##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -147,28 +163,58 @@ private object ErrorClassesJsonReader {
  * @param subClass SubClass associated with this class.
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+    breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
 /**
  * Information associated with an error subclass.
  *
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
-private case class ErrorSubInfo(message: Seq[String]) {
+private case class ErrorSubInfo(message: Seq[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+      breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
+/**
+ * Additional information if the error was caused by a breaking change.
+ *
+ * @param migrationMessage A message explaining how the user can migrate their job to work
+ *                         with the breaking change.
+ * @param mitigationSparkConfig A spark config flag that can be used to mitigate the
+ *                              breaking change.
+ * @param autoMitigation If true, the spark job can be automatically retried by setting the
+ *                       mitigationSparkConfig. If false, the breaking change must be
+ *                       mitigated manually.
+ */
+case class BreakingChangeInfo(
+  migrationMessage: Seq[String],

Review Comment:
   Done



##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -147,28 +163,58 @@ private object ErrorClassesJsonReader {
  * @param subClass SubClass associated with this class.
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+    breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
 /**
  * Information associated with an error subclass.
  *
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
-private case class ErrorSubInfo(message: Seq[String]) {
+private case class ErrorSubInfo(message: Seq[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+      breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
+/**
+ * Additional information if the error was caused by a breaking change.
+ *
+ * @param migrationMessage A message explaining how the user can migrate their job to work
+ *                         with the breaking change.
+ * @param mitigationSparkConfig A spark config flag that can be used to mitigate the
+ *                              breaking change.
+ * @param autoMitigation If true, the spark job can be automatically retried by setting the
+ *                       mitigationSparkConfig. If false, the breaking change must be
+ *                       mitigated manually.
+ */
+case class BreakingChangeInfo(
+  migrationMessage: Seq[String],
+  mitigationSparkConfig: Option[MitigationSparkConfig] = None,
+  autoMitigation: Boolean = false
+)
+
+/**
+ * A spark config flag that can be used to mitigate a breaking change.
+ * @param key The spark config key.
+ * @param value The spark config value that mitigates the breaking change.
+ */
+case class MitigationSparkConfig(key: String, value: String)

Review Comment:
   Done



##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -147,28 +163,58 @@ private object ErrorClassesJsonReader {
  * @param subClass SubClass associated with this class.
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+    breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
 /**
  * Information associated with an error subclass.
  *
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
-private case class ErrorSubInfo(message: Seq[String]) {
+private case class ErrorSubInfo(message: Seq[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {

Review Comment:
   Done



##########
core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala:
##########
@@ -504,6 +504,90 @@ class SparkThrowableSuite extends SparkFunSuite {
     }
   }
 
+  test("breaking changes info") {
+    assert(SparkThrowableHelper.getBreakingChangeInfo(null).isEmpty)
+
+    val nonBreakingChangeError = new SparkException(
+      errorClass = "CANNOT_PARSE_DECIMAL",
+      messageParameters = Map.empty[String, String],
+      cause = null)
+    assert(nonBreakingChangeError.getBreakingChangeInfo == null)
+
+    withTempDir { dir =>
+      val json = new File(dir, "errors.json")
+      Files.writeString(
+        json.toPath,
+        """
+          |{
+          |  "TEST_ERROR": {
+          |    "message": [
+          |      "Error message 1 with <param1>."
+          |    ],
+          |    "breakingChangeInfo": {
+          |      "migrationMessage": [
+          |        "Migration message with <param2>."
+          |      ],
+          |      "mitigationSparkConfig": {
+          |        "key": "config.key1",
+          |        "value": "config.value1"
+          |      },
+          |      "autoMitigation": true
+          |    }
+          |  },
+          |  "TEST_ERROR_WITH_SUBCLASS": {
+          |    "message": [
+          |      "Error message 2 with <param1>."
+          |    ],
+          |    "subClass": {
+          |      "SUBCLASS": {
+          |        "message": [
+          |          "Subclass message with <param2>."
+          |        ],
+          |        "breakingChangeInfo": {
+          |          "migrationMessage": [
+          |            "Subclass migration message with <param3>."
+          |          ],
+          |          "mitigationSparkConfig": {
+          |            "key": "config.key2",
+          |            "value": "config.value2"
+          |          },
+          |          "autoMitigation": false
+          |        }
+          |      }
+          |    }
+          |  }
+          |}
+          |""".stripMargin,
+        StandardCharsets.UTF_8)
+
+      val error1Params = Map("param1" -> "value1", "param2" -> "value2")
+      val error2Params = Map("param1" -> "value1", "param2" -> "value2", "param3" -> "value3")
+
+      val reader =
+        new ErrorClassesJsonReader(Seq(errorJsonFilePath.toUri.toURL, json.toURI.toURL))
+      val errorMessage = reader.getErrorMessage("TEST_ERROR", error1Params)
+      assert(errorMessage == "Error message 1 with value1. Migration message with value2.")
+      val breakingChangeInfo = reader.getBreakingChangeInfo("TEST_ERROR")
+      assert(
+        breakingChangeInfo.contains(
+          BreakingChangeInfo(
+            Seq("Migration message with <param2>."),
+            Some(MitigationSparkConfig("config.key1", "config.value1")),
+            autoMitigation = true)))
+      val errorMessage2 =
+        reader.getErrorMessage("TEST_ERROR_WITH_SUBCLASS.SUBCLASS", error2Params)
+      assert(
+        errorMessage2 == "Error message 2 with value1. Subclass message with value2." +
+          " Subclass migration message with value3.")
+      val breakingChangeInfo2 = reader.getBreakingChangeInfo("TEST_ERROR_WITH_SUBCLASS.SUBCLASS")
+      assert(
+        breakingChangeInfo2.contains(
+          BreakingChangeInfo(
+            Seq("Subclass migration message with <param3>."),
+            Some(MitigationSparkConfig("config.key2", "config.value2")))))
+    }
+  }

Review Comment:
   That code is not written in a testable way. The `errorReader` object is hardcoded here: https://github.com/apache/spark/blob/0fb89df2df10cbec394b3723373716d2ee1c1c33/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala#L34-L38
   instead of using a style like dependency injection.
   
   I was able to manually test locally by updated `error-conditions.json` with a fake error message:
   
   ```
     "TEST_ERROR" : {
       "message" : [
         "Error message 1 with <param1>."
       ],
       "sqlState" : "42845",
       "breakingChangeInfo" : {
         "migrationMessage" : [
           "Migration message with <param2>."
         ],
         "mitigationConfig" : {
           "key" : "config.key1",
           "value" : "config.value1"
         },
         "needsAudit" : false
       }
     },
     ```
     
     And writing a test in `SparkThrowableSuite`:
     ```
         val error = new SparkException(
         errorClass = "TEST_ERROR",
         messageParameters = Map("param1" -> "value1", "param2" -> "value2"),
         cause = null)
       assert(SparkThrowableHelper.getMessage(error, ErrorMessageFormat.STANDARD) ==
         """{
           |  "errorClass" : "TEST_ERROR",
           |  "messageTemplate" : "Error message 1 with <param1>. Migration message with <param2>.",
           |  "breakingChangeInfo" : {
           |    "migrationMessage" : "Migration message with <param2>.",
           |    "mitigationConfig" : {
           |      "key" : "config.key1",
           |      "value" : "config.value1"
           |    },
           |    "needsAudit" : false
           |  },
           |  "sqlState" : "42845",
           |  "messageParameters" : {
           |    "param1" : "value1",
           |    "param2" : "value2"
           |  }
           |}""".stripMargin)
   
   ```
   
   But I'm not sure that it's ok to add fake errors to `error-conditions.json`.



##########
common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -99,6 +107,19 @@ private[spark] object SparkThrowableHelper {
           g.writeStringField("errorClass", errorClass)
           if (format == STANDARD) {
             g.writeStringField("messageTemplate", errorReader.getMessageTemplate(errorClass))
+            errorReader.getBreakingChangeInfo(errorClass).foreach{ breakingChangeInfo =>
+              g.writeObjectFieldStart("breakingChangeInfo")
+              g.writeStringField("migrationMessage",
+                  breakingChangeInfo.migrationMessage.mkString("\n"))
+              breakingChangeInfo.mitigationSparkConfig.foreach{ mitigationSparkConfig =>
+                g.writeObjectFieldStart("mitigationSparkConfig")

Review Comment:
   This is not an array, it's just an `Option`



##########
common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -99,6 +107,19 @@ private[spark] object SparkThrowableHelper {
           g.writeStringField("errorClass", errorClass)
           if (format == STANDARD) {
             g.writeStringField("messageTemplate", errorReader.getMessageTemplate(errorClass))
+            errorReader.getBreakingChangeInfo(errorClass).foreach{ breakingChangeInfo =>

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #52256:
URL: https://github.com/apache/spark/pull/52256#issuecomment-3304811929

   Merged to master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2354393219


##########
sql/connect/common/src/main/protobuf/spark/connect/base.proto:
##########
@@ -1095,6 +1095,32 @@ message FetchErrorDetailsResponse {
     // Portable error identifier across SQL engines
     // If null, error class or SQLSTATE is not set.
     optional string sql_state = 4;
+
+    // Additional information if the error was caused by a breaking change.
+    optional BreakingChangeInfo breaking_change_info = 5;
+  }
+
+  // BreakingChangeInfo defines the schema for breaking change information.
+  message BreakingChangeInfo {
+    // A message explaining how the user can migrate their job to work
+    // with the breaking change.
+    repeated string migration_message = 1;

Review Comment:
   shall we concatenate the string in the server side? For client's point of view, it's a bit weird to see the message as a list of string.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2354387018


##########
python/pyspark/errors/exceptions/connect.py:
##########
@@ -241,6 +260,15 @@ def getMessage(self) -> str:
     def getGrpcStatusCode(self) -> grpc.StatusCode:
         return self._grpc_status_code
 
+    def getBreakingChangeInfo(self) -> Optional[Dict[str, Any]]:

Review Comment:
   shall we add a `BreakingChangeInfo` class in python as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2361526574


##########
sql/connect/common/src/main/protobuf/spark/connect/base.proto:
##########
@@ -1095,6 +1095,32 @@ message FetchErrorDetailsResponse {
     // Portable error identifier across SQL engines
     // If null, error class or SQLSTATE is not set.
     optional string sql_state = 4;
+
+    // Additional information if the error was caused by a breaking change.
+    optional BreakingChangeInfo breaking_change_info = 5;
+  }
+
+  // BreakingChangeInfo defines the schema for breaking change information.
+  message BreakingChangeInfo {
+    // A message explaining how the user can migrate their job to work
+    // with the breaking change.
+    repeated string migration_message = 1;

Review Comment:
   It's a string list in JSON because we don't want to have super long lines in the JSON file. It's not really about semantic and I think we should not inherit this trick in the protobuf message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2378561779


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -147,28 +163,59 @@ private object ErrorClassesJsonReader {
  * @param subClass SubClass associated with this class.
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
 private case class ErrorInfo(
     message: Seq[String],
     subClass: Option[Map[String, ErrorSubInfo]],
-    sqlState: Option[String]) {
+    sqlState: Option[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+    breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
 /**
  * Information associated with an error subclass.
  *
  * @param message Message format with optional placeholders (e.g. &lt;parm&gt;).
  *                The error message is constructed by concatenating the lines with newlines.
+ * @param breakingChangeInfo Additional metadata if the error is due to a breaking change.
  */
-private case class ErrorSubInfo(message: Seq[String]) {
+private case class ErrorSubInfo(
+    message: Seq[String],
+    breakingChangeInfo: Option[BreakingChangeInfo] = None) {
   // For compatibility with multi-line error messages
   @JsonIgnore
-  val messageTemplate: String = message.mkString("\n")
+  val messageTemplate: String = message.mkString("\n") +
+      breakingChangeInfo.map(_.migrationMessage.mkString(" ", "\n", "")).getOrElse("")
 }
 
+/**
+ * Additional information if the error was caused by a breaking change.
+ *
+ * @param migrationMessage A message explaining how the user can migrate their job to work
+ *                         with the breaking change.
+ * @param mitigationConfig A spark config flag that can be used to mitigate the
+ *                              breaking change.
+ * @param needsAudit If true, the breaking change should be inspected manually.
+ *                       If false, the spark job should be retried by setting the
+ *                       mitigationConfig.
+ */
+case class BreakingChangeInfo(

Review Comment:
   I just realize that we expose it as a public API via `SparkThrowable.getBreakingChangeInfo`. We shouldn't expose a case class as public API as it has a wide API surface, including the companion object.
   
   We should follow `SparkThrowable` and define it in Java.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2342947996


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -46,24 +46,28 @@ class ErrorClassesJsonReader(jsonFileURLs: Seq[URL]) {
       case (key, value) => key -> value
     }
     val sub = new StringSubstitutor(sanitizedParameters)
-    val errorMessage = try {
-      sub.replace(ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(
-        messageTemplate, "\\$\\{$1\\}"))
-    } catch {
-      case i: IllegalArgumentException => throw SparkException.internalError(
-        s"Undefined error message parameter for error class: '$errorClass', " +
-          s"MessageTemplate: $messageTemplate, " +
-          s"Parameters: $messageParameters", i)
-    }
+    val errorMessage =
+      try {
+        sub.replace(
+          ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(messageTemplate, "\\$\\{$1\\}"))
+      } catch {
+        case i: IllegalArgumentException =>
+          throw SparkException.internalError(
+            s"Undefined error message parameter for error class: '$errorClass', " +
+              s"MessageTemplate: $messageTemplate, " +
+              s"Parameters: $messageParameters",
+            i)
+      }
     if (util.SparkEnvUtils.isTesting) {
-      val placeHoldersNum = ErrorClassesJsonReader.TEMPLATE_REGEX.findAllIn(messageTemplate).length
+      val placeHoldersNum =

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2342956340


##########
common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -37,15 +37,11 @@ private[spark] object SparkThrowableHelper {
     // of this ticket: https://issues.apache.org/jira/browse/SPARK-47429
     Seq(SparkClassUtils.getSparkClassLoader.getResource("error/error-conditions.json")))
 
-  def getMessage(
-      errorClass: String,
-      messageParameters: Map[String, String]): String = {
+  def getMessage(errorClass: String, messageParameters: Map[String, String]): String = {

Review Comment:
   let's exclude these code style only changes from the PR 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2342945504


##########
common/utils/src/main/java/org/apache/spark/SparkThrowable.java:
##########
@@ -60,6 +61,11 @@ default boolean isInternalError() {
     return SparkThrowableHelper.isInternalError(this.getCondition());
   }
 
+  default Optional<BreakingChangeInfo> getBreakingChangeInfo() {

Review Comment:
   let's follow other methods in this class and use `null` to indicate not present.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507]Add breaking change info to errors [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2342947331


##########
common/utils/src/main/scala/org/apache/spark/ErrorClassesJSONReader.scala:
##########
@@ -46,24 +46,28 @@ class ErrorClassesJsonReader(jsonFileURLs: Seq[URL]) {
       case (key, value) => key -> value
     }
     val sub = new StringSubstitutor(sanitizedParameters)
-    val errorMessage = try {
-      sub.replace(ErrorClassesJsonReader.TEMPLATE_REGEX.replaceAllIn(
-        messageTemplate, "\\$\\{$1\\}"))
-    } catch {
-      case i: IllegalArgumentException => throw SparkException.internalError(
-        s"Undefined error message parameter for error class: '$errorClass', " +
-          s"MessageTemplate: $messageTemplate, " +
-          s"Parameters: $messageParameters", i)
-    }
+    val errorMessage =

Review Comment:
   unnecessary code style change



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-53507][CONNECT] Add breaking change info to errors [spark]

Posted by "imarkowitz (via GitHub)" <gi...@apache.org>.
imarkowitz commented on code in PR #52256:
URL: https://github.com/apache/spark/pull/52256#discussion_r2356754559


##########
python/pyspark/errors/exceptions/connect.py:
##########
@@ -241,6 +260,15 @@ def getMessage(self) -> str:
     def getGrpcStatusCode(self) -> grpc.StatusCode:
         return self._grpc_status_code
 
+    def getBreakingChangeInfo(self) -> Optional[Dict[str, Any]]:

Review Comment:
   We have a proto class defined in `sql/connect/common/src/main/protobuf/spark/connect/base.proto` but I didn't want to introduce that as a dependency here



##########
sql/connect/common/src/main/protobuf/spark/connect/base.proto:
##########
@@ -1095,6 +1095,32 @@ message FetchErrorDetailsResponse {
     // Portable error identifier across SQL engines
     // If null, error class or SQLSTATE is not set.
     optional string sql_state = 4;
+
+    // Additional information if the error was caused by a breaking change.
+    optional BreakingChangeInfo breaking_change_info = 5;
+  }
+
+  // BreakingChangeInfo defines the schema for breaking change information.
+  message BreakingChangeInfo {
+    // A message explaining how the user can migrate their job to work
+    // with the breaking change.
+    repeated string migration_message = 1;

Review Comment:
   I think it's fine either way. The migration message is also returned as part of the error message, so I think that's the main way end users would interact with it. Instead of doing a conversion here I thought I would just return the value in the same format it's defined in.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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