You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ge...@apache.org on 2022/05/26 07:26:01 UTC
[spark] branch branch-3.3 updated: [SPARK-39234][SQL][3.3] Code clean up in SparkThrowableHelper.getMessage
This is an automated email from the ASF dual-hosted git repository.
gengliang pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new 997e7f0af50 [SPARK-39234][SQL][3.3] Code clean up in SparkThrowableHelper.getMessage
997e7f0af50 is described below
commit 997e7f0af506410d76f1232acc00ad9518e9a804
Author: Gengliang Wang <ge...@apache.org>
AuthorDate: Thu May 26 15:25:40 2022 +0800
[SPARK-39234][SQL][3.3] 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 #36669 from gengliangwang/portSPARK-39234.
Authored-by: Gengliang Wang <ge...@apache.org>
Signed-off-by: Gengliang Wang <ge...@apache.org>
---
core/src/main/scala/org/apache/spark/ErrorInfo.scala | 7 ++++++-
.../main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala | 2 +-
.../scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala | 3 +--
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/core/src/main/scala/org/apache/spark/ErrorInfo.scala b/core/src/main/scala/org/apache/spark/ErrorInfo.scala
index 41c0e83f917..99e081ebb45 100644
--- a/core/src/main/scala/org/apache/spark/ErrorInfo.scala
+++ b/core/src/main/scala/org/apache/spark/ErrorInfo.scala
@@ -61,8 +61,13 @@ private[spark] object SparkThrowableHelper {
queryContext: String = ""): String = {
val errorInfo = errorClassToInfoMap.getOrElse(errorClass,
throw new IllegalArgumentException(s"Cannot find error class '$errorClass'"))
+ val displayQueryContext = if (queryContext.isEmpty) {
+ ""
+ } else {
+ s"\n$queryContext"
+ }
String.format(errorInfo.messageFormat.replaceAll("<[a-zA-Z0-9_-]+>", "%s"),
- messageParameters: _*) + queryContext
+ messageParameters: _*) + 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 079abd3f2e0..09d24c5f811 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-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org