You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2022/07/28 04:45:02 UTC

[spark] branch master updated: [SPARK-39899][SQL] Fix passing of message parameters to `InvalidUDFClassException`

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

maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 378c207345a [SPARK-39899][SQL] Fix passing of message parameters to `InvalidUDFClassException`
378c207345a is described below

commit 378c207345a3ac16d1ad5acbeaec4653418396b9
Author: Max Gekk <ma...@gmail.com>
AuthorDate: Thu Jul 28 09:44:47 2022 +0500

    [SPARK-39899][SQL] Fix passing of message parameters to `InvalidUDFClassException`
    
    ### What changes were proposed in this pull request?
    In the PR, I propose to pass `messageParameters` to `AnalysisException` from `InvalidUDFClassException`.
    
    Also, I propose to replace `checkErrorClass` by `checkError` in the test "NO_HANDLER_FOR_UDAF: No handler for UDAF error" to check that the message parameters are passed correctly, and make the test independent from the message of the error class `NO_HANDLER_FOR_UDAF`.
    
    ### Why are the changes needed?
    To fix a bug and provide actual message parameters to users.
    
    ### Does this PR introduce _any_ user-facing change?
    Yes. After the changes, users receive non-empty message parameters.
    
    ### How was this patch tested?
    By running the modified test suite:
    ```
    $ build/sbt "sql/testOnly *QueryCompilationErrorsSuite"
    ```
    
    Closes #37323 from MaxGekk/override-getMessageParameters.
    
    Authored-by: Max Gekk <ma...@gmail.com>
    Signed-off-by: Max Gekk <ma...@gmail.com>
---
 .../spark/sql/catalyst/catalog/InvalidUDFClassException.scala | 11 ++++++++---
 .../apache/spark/sql/errors/QueryCompilationErrorsSuite.scala |  5 ++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InvalidUDFClassException.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InvalidUDFClassException.scala
index 28918d1799c..4d83663fd31 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InvalidUDFClassException.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InvalidUDFClassException.scala
@@ -26,9 +26,14 @@ import org.apache.spark.sql.AnalysisException
  */
 class InvalidUDFClassException private[sql](
     message: String,
-    errorClass: Option[String] = None)
-  extends AnalysisException(message = message, errorClass = errorClass) {
+    errorClass: Option[String] = None,
+    messageParameters: Array[String] = Array.empty)
+  extends AnalysisException(
+    message = message, errorClass = errorClass, messageParameters = messageParameters) {
 
   def this(errorClass: String, messageParameters: Array[String]) =
-    this(SparkThrowableHelper.getMessage(errorClass, null, messageParameters), Some(errorClass))
+    this(
+      SparkThrowableHelper.getMessage(errorClass, null, messageParameters),
+      Some(errorClass),
+      messageParameters)
 }
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
index af4a83f5e5e..667fc1df42c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
@@ -208,11 +208,10 @@ class QueryCompilationErrorsSuite
       val e = intercept[AnalysisException] (
         sql(s"SELECT $functionName(123) as value")
       )
-      checkErrorClass(
+      checkError(
         exception = e,
         errorClass = "NO_HANDLER_FOR_UDAF",
-        msg = "No handler for UDAF 'org.apache.spark.sql.errors.MyCastToString'. " +
-          "Use sparkSession.udf.register(...) instead.; line 1 pos 7")
+        parameters = Map("functionName" -> "org.apache.spark.sql.errors.MyCastToString"))
     }
   }
 


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