Skip to content

[SPARK-55109][SQL] Enhance RaiseError to generate valid SQL#55115

Open
felipepessoto wants to merge 2 commits intoapache:masterfrom
felipepessoto:raise_error_sql_fix
Open

[SPARK-55109][SQL] Enhance RaiseError to generate valid SQL#55115
felipepessoto wants to merge 2 commits intoapache:masterfrom
felipepessoto:raise_error_sql_fix

Conversation

@felipepessoto
Copy link
Copy Markdown

@felipepessoto felipepessoto commented Mar 31, 2026

What changes were proposed in this pull request?

Fix RaiseError.sql: [SPARK-55109] RaiseError(xyz).sql is broken in 4.0

Repro:

import org.apache.spark.sql.catalyst.expressions.{Literal, RaiseError}
println(RaiseError(Literal("error!")).sql)

3.5 generates valid SQL:

raise_error('error!')

4.0:
raise_error('USER_RAISED_EXCEPTION', map('errorMessage', 'error!'))

Why are the changes needed?

To fix the regression in 4.0

Does this PR introduce any user-facing change?

Bug fix, now it generates valid SQL.

How was this patch tested?

New unit test.

image image

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Github Copilot v1.0.14-0

@felipepessoto
Copy link
Copy Markdown
Author

@cloud-fan, @dbatomic ^

@felipepessoto felipepessoto changed the title [SPARK-55109][SQL] Enhance RaiseError to support valid SQL [SPARK-55109][SQL] Enhance RaiseError to generate valid SQL Mar 31, 2026

override def sql: String = {
// When constructed from the single-argument form (just an error message string),
// output only the original message to produce valid, roundtrippable SQL.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we check the errorClass as well? to be _LEGACY_ERROR_USER_RAISED_EXCEPTION or USER_RAISED_EXCEPTION

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and tests are re-run:

image

…s is USER_RAISED_EXCEPTION or _LEGACY_ERROR_USER_RAISED_EXCEPTION, which are the two values set by the single-argument constructor. A custom errorClass now falls through to the two-argument form.
@felipepessoto
Copy link
Copy Markdown
Author

Thanks @cloud-fan. I believe I addressed the feedback. Could you check again, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants