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 8cec63383085 [SPARK-46558][CONNECT] Extract a helper function to eliminate the duplicate code that retrieves `MessageParameters` from `ErrorParams` in `GrpcExceptionConverter` 8cec63383085 is described below commit 8cec633830855f20348165daafa68877322b345d Author: yangjie01 <yangji...@baidu.com> AuthorDate: Tue Jan 2 15:07:01 2024 +0300 [SPARK-46558][CONNECT] Extract a helper function to eliminate the duplicate code that retrieves `MessageParameters` from `ErrorParams` in `GrpcExceptionConverter` ### What changes were proposed in this pull request? This pr extract a helper funciton `errorParamsToMessageParameters` to eliminate the duplicate code that retrieves `MessageParameters` from `ErrorParams` in `GrpcExceptionConverter` ### Why are the changes needed? Eliminate the duplicate code. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Pass GitHub Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes #44554 from LuciferYang/SPARK-46558. Authored-by: yangjie01 <yangji...@baidu.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- .../connect/client/GrpcExceptionConverter.scala | 52 ++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala b/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala index 6641e8c73fc7..8abfd06d4a3f 100644 --- a/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala +++ b/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala @@ -199,10 +199,7 @@ private[client] object GrpcExceptionConverter { errorConstructor(params => new AnalysisException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3100"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), cause = params.cause, context = params.queryContext)), errorConstructor(params => @@ -227,50 +224,32 @@ private[client] object GrpcExceptionConverter { errorConstructor[NumberFormatException](params => new SparkNumberFormatException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3104"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), params.queryContext)), errorConstructor[IllegalArgumentException](params => new SparkIllegalArgumentException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3105"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), params.queryContext, cause = params.cause.orNull)), errorConstructor[ArithmeticException](params => new SparkArithmeticException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3106"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), params.queryContext)), errorConstructor[UnsupportedOperationException](params => new SparkUnsupportedOperationException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3107"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - })), + messageParameters = errorParamsToMessageParameters(params))), errorConstructor[ArrayIndexOutOfBoundsException](params => new SparkArrayIndexOutOfBoundsException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3108"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), params.queryContext)), errorConstructor[DateTimeException](params => new SparkDateTimeException( errorClass = params.errorClass.getOrElse("_LEGACY_ERROR_TEMP_3109"), - messageParameters = params.errorClass match { - case Some(_) => params.messageParameters - case None => Map("message" -> params.message) - }, + messageParameters = errorParamsToMessageParameters(params), params.queryContext)), errorConstructor(params => new SparkRuntimeException( @@ -389,4 +368,21 @@ private[client] object GrpcExceptionConverter { errorsToThrowable(0, Seq(builder.build())) } + + /** + * This method is used to convert error parameters to message parameters. + * + * @param params + * The error parameters to be converted. + * @return + * A Map of message parameters. If the error class is defined in the params, it returns the + * message parameters from the params. If the error class is not defined, it returns a new Map + * with a single entry where the key is "message" and the value is the message from the + * params. + */ + private def errorParamsToMessageParameters(params: ErrorParams): Map[String, String] = + params.errorClass match { + case Some(_) => params.messageParameters + case None => Map("message" -> params.message) + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org