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 ebd916b0054 [SPARK-39234][SQL] Code clean up in SparkThrowableHelper.getMessage ebd916b0054 is described below commit ebd916b005499c724bbec54b3df85cd28a864e03 Author: Gengliang Wang <gengli...@apache.org> AuthorDate: Thu May 19 19:13:15 2022 +0300 [SPARK-39234][SQL] Code clean up in SparkThrowableHelper.getMessage ### What changes were proposed in this pull request? 1. Remove the starting "\n" in `Origin.context`. The "\n" will be append in the method `SparkThrowableHelper.getMessage` instead. 2. Code clean up the method SparkThrowableHelper.getMessage to eliminate redundant code. ### Why are the changes needed? Code clean up to eliminate redundant code. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing UT Closes #36612 from gengliangwang/moveNewLine. Authored-by: Gengliang Wang <gengli...@apache.org> Signed-off-by: Max Gekk <max.g...@gmail.com> --- .../src/main/scala/org/apache/spark/ErrorInfo.scala | 21 +++++++++++++-------- .../apache/spark/sql/catalyst/trees/TreeNode.scala | 2 +- .../spark/sql/catalyst/trees/TreeNodeSuite.scala | 3 +-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/ErrorInfo.scala b/core/src/main/scala/org/apache/spark/ErrorInfo.scala index e11e6485851..4639e56aa50 100644 --- a/core/src/main/scala/org/apache/spark/ErrorInfo.scala +++ b/core/src/main/scala/org/apache/spark/ErrorInfo.scala @@ -77,20 +77,25 @@ private[spark] object SparkThrowableHelper { queryContext: String = ""): String = { val errorInfo = errorClassToInfoMap.getOrElse(errorClass, throw new IllegalArgumentException(s"Cannot find error class '$errorClass'")) - if (errorInfo.subClass.isDefined) { + val (displayClass, displayMessageParameters, displayFormat) = if (errorInfo.subClass.isEmpty) { + (errorClass, messageParameters, errorInfo.messageFormat) + } else { val subClass = errorInfo.subClass.get val subErrorClass = messageParameters.head val errorSubInfo = subClass.getOrElse(subErrorClass, throw new IllegalArgumentException(s"Cannot find sub error class '$subErrorClass'")) - val subMessageParameters = messageParameters.tail - "[" + errorClass + "." + subErrorClass + "] " + String.format((errorInfo.messageFormat + - errorSubInfo.messageFormat).replaceAll("<[a-zA-Z0-9_-]+>", "%s"), - subMessageParameters: _*) + queryContext + (errorClass + "." + subErrorClass, messageParameters.tail, + errorInfo.messageFormat + errorSubInfo.messageFormat) + } + val displayMessage = String.format( + displayFormat.replaceAll("<[a-zA-Z0-9_-]+>", "%s"), + displayMessageParameters : _*) + val displayQueryContext = if (queryContext.isEmpty) { + "" } else { - "[" + errorClass + "] " + String.format( - errorInfo.messageFormat.replaceAll("<[a-zA-Z0-9_-]+>", "%s"), - messageParameters: _*) + queryContext + s"\n$queryContext" } + s"[$displayClass] $displayMessage$displayQueryContext" } def getSqlState(errorClass: String): String = { diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala index 0714898e19d..54c64515ee4 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala @@ -89,7 +89,7 @@ case class Origin( "" } val builder = new StringBuilder - builder ++= s"\n== SQL$objectContext$positionContext ==\n" + builder ++= s"== SQL$objectContext$positionContext ==\n" val text = sqlText.get val start = math.max(startIndex.get, 0) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala index ffbc5d89bdb..899a740bdae 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala @@ -876,8 +876,7 @@ class TreeNodeSuite extends SparkFunSuite with SQLHelper { objectType = Some("VIEW"), objectName = Some("some_view")) val expected = - """ - |== SQL of VIEW some_view(line 3, position 38) == + """== SQL of VIEW some_view(line 3, position 38) == |...7890 + 1234567890 + 1234567890, cast('a' | ^^^^^^^^ |as /* comment */ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org