-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-44838][SQL] raise_error improvement
### What changes were proposed in this pull request? Extend the raise_error() function to a two-argument version: raise_error(errorClassStr, errorParamMap) This new form will accept any error class defined in error-classes.json and require Map<String, String> to provide values for the parameters in the error classes template. Externally an error raised via raise_error() is indistinguishable from an error raised from within the Spark engine. The single-parameter raise_error(str) will raise USER_RAISED_EXCEPTION (SQLSTATE P0001 - borrowed from PostgreSQL). USER_RAISED_EXCEPTION text is: "<errorMessage>" which will be filled in with the str - value. We will also provide `spark.sql.legacy.raiseErrorWithoutErrorClass` (default: false) to revert to the old behavior for the single-parameter version. Naturally assert_true() will also return `USER_RAISED_EXCEPTION`. #### Examples ``` SELECT raise_error('VIEW_NOT_FOUND', map('relationName', '`v1`'); [VIEW_NOT_FOUND] The view `v1` cannot be found. Verify the spelling ... SELECT raise_error('Error!'); [USER_RAISED_EXCEPTION] Error! SELECT assert_true(1 < 0); [USER_RAISED_EXCEPTION] '(1 < 0)' is not true! SELECT assert_true(1 < 0, 'bad!') [USER_RAISED_EXCEPTION] bad! ``` ### Why are the changes needed? This change moves raise_error() and assert_true() to the new error frame work. It greatly expands the ability of users to raise error messages which can be intercepted via SQLSTATE and/or error class. ### Does this PR introduce _any_ user-facing change? Yes, the result of assert_true() changes and raise_error() gains a new signature. ### How was this patch tested? Run existing QA and add new tests for assert_true and raise_error ### Was this patch authored or co-authored using generative AI tooling? No Closes #42985 from srielau/SPARK-44838-raise_error. Lead-authored-by: srielau <serge@rielau.com> Co-authored-by: Serge Rielau <srielau@users.noreply.github.com> Co-authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: Gengliang Wang <gengliang@apache.org>
- Loading branch information
1 parent
8399dd3
commit 9109d70
Showing
23 changed files
with
551 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../src/test/resources/query-tests/explain-results/function_assert_true_with_message.explain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Project [if ((id#0L > cast(0 as bigint))) null else raise_error(id negative!, NullType) AS assert_true((id > 0), id negative!)#0] | ||
Project [if ((id#0L > cast(0 as bigint))) null else raise_error(USER_RAISED_EXCEPTION, map(errorMessage, id negative!), NullType) AS assert_true((id > 0), id negative!)#0] | ||
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0] |
2 changes: 1 addition & 1 deletion
2
...onnect/common/src/test/resources/query-tests/explain-results/function_raise_error.explain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Project [raise_error(kaboom, NullType) AS raise_error(kaboom)#0] | ||
Project [raise_error(USER_RAISED_EXCEPTION, map(errorMessage, kaboom), NullType) AS raise_error(USER_RAISED_EXCEPTION, map(errorMessage, kaboom))#0] | ||
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.