Commit 8d64cb4
[SPARK-46360][PYTHON] Enhance error message debugging with new
### What changes were proposed in this pull request?
This PR proposes to introduce `getMessage` to provide a standardized way for users to obtain a concise and clear error message.
### Why are the changes needed?
Previously, extracting a simple and informative error message in PySpark was not straightforward. The internal `ErrorClassesReader.get_error_message` method was often used, but for JVM-originated errors not defined in `error_classes.py`, obtaining a succinct error message was challenging.
The new `getMessage` API harmonizes error message retrieval across PySpark, leveraging existing JVM implementations to ensure consistency and clarity in the messages presented to the users.
### Does this PR introduce _any_ user-facing change?
Yes, this PR introduces a `getMessage` for directly accessing simplified error messages in PySpark.
- **Before**: No official API for simplified error messages; excessive details in the error output:
```python
from pyspark.sql.utils import AnalysisException
try:
spark.sql("""SELECT a""")
except AnalysisException as e:
str(e)
# "[UNRESOLVED_COLUMN.WITHOUT_SUGGESTION] A column, variable, or function parameter with name `a` cannot be resolved. SQLSTATE: 42703; line 1 pos 7;\n'Project ['a]\n+- OneRowRelation\n"
```
- **After**: The `getMessage` API provides streamlined, user-friendly error messages:
```python
from pyspark.sql.utils import AnalysisException
try:
spark.sql("""SELECT a""")
except AnalysisException as e:
e.getMessage()
# '[UNRESOLVED_COLUMN.WITHOUT_SUGGESTION] A column, variable, or function parameter with name `a` cannot be resolved. SQLSTATE: 42703'
```
### How was this patch tested?
Added UTs.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #44292 from itholic/getMessage.
Authored-by: Haejoon Lee <haejoon.lee@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>getMessage API1 parent 2a49fee commit 8d64cb4
3 files changed
Lines changed: 44 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
96 | 113 | | |
97 | 114 | | |
98 | | - | |
| 115 | + | |
99 | 116 | | |
100 | 117 | | |
101 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
121 | 139 | | |
122 | 140 | | |
123 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1750 | 1750 | | |
1751 | 1751 | | |
1752 | 1752 | | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1753 | 1760 | | |
1754 | 1761 | | |
1755 | 1762 | | |
1756 | 1763 | | |
1757 | 1764 | | |
1758 | 1765 | | |
1759 | 1766 | | |
| 1767 | + | |
1760 | 1768 | | |
1761 | 1769 | | |
1762 | 1770 | | |
| |||
0 commit comments