Skip to content

[SPARK-52184][SQL] Wrap external engine JDBC syntax errors with a unified exception #50918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

alekjarmov
Copy link
Contributor

@alekjarmov alekjarmov commented May 16, 2025

What changes were proposed in this pull request?

This PR introduces a unified mechanism for handling SQL syntax errors thrown by external JDBC engines. It does so by:

  • Adding a new error condition: JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR.
  • Extending multiple JdbcDialect implementations to provide best-effort syntax error detection via isSyntaxErrorBestEffort.
  • Updating integration test suites to include a new shared test that verifies the wrapping behavior.

Why are the changes needed?

Current behavior rethrows the error if it's a syntax error on the external engine. Having it wrapped in a Spark exception enables for easier data scince.

Does this PR introduce any user-facing change?

The users would get a better error message.

How was this patch tested?

Adding new integration tests.

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

Coauthored with GitHub Copilot.

@github-actions github-actions bot added the SQL label May 16, 2025
@MaxGekk
Copy link
Member

MaxGekk commented May 19, 2025

@alekjarmov Could you fix formatting, please:

[info] SparkThrowableSuite:
[info] - No duplicate error classes (27 milliseconds)
[info] - Error conditions are correctly formatted *** FAILED *** (143 milliseconds)

just re-generate the json file:

$ SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "core/testOnly *SparkThrowableSuite -- -t \"Error conditions are correctly formatted\""

@alekjarmov alekjarmov force-pushed the wrap-external-engine-errors branch from 6898200 to 8b143e5 Compare May 19, 2025 08:53
@alekjarmov alekjarmov force-pushed the wrap-external-engine-errors branch from 8b143e5 to 2aacaf9 Compare May 19, 2025 09:43
@alekjarmov
Copy link
Contributor Author

@cloud-fan Could you merge it please if everything is ok?

@@ -3876,6 +3876,24 @@
},
"sqlState" : "42000"
},
"JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR" : {
"message" : [
"JDBC external engine syntax error."
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to always provide the compiled JDBC SQL text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I modified the error message to include the query.

@cloud-fan
Copy link
Contributor

The last commit just modified the version number in @Since, no need to run tests again. I'm merging it to master, thanks!

@cloud-fan cloud-fan closed this in e7627b1 May 20, 2025
yhuang-db pushed a commit to yhuang-db/spark that referenced this pull request Jun 9, 2025
…fied exception

### What changes were proposed in this pull request?

This PR introduces a unified mechanism for handling SQL syntax errors thrown by external JDBC engines. It does so by:
* Adding a new error condition: `JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR`.
* Extending multiple JdbcDialect implementations to provide best-effort syntax error detection via `isSyntaxErrorBestEffort`.
 * Updating integration test suites to include a new shared test that verifies the wrapping behavior.

### Why are the changes needed?

Current behavior rethrows the error if it's a syntax error on the external engine. Having it wrapped in a Spark exception enables for easier data scince.

### Does this PR introduce _any_ user-facing change?

The users would get a better error message.

### How was this patch tested?

Adding new integration tests.

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

Coauthored with GitHub Copilot.

Closes apache#50918 from alekjarmov/wrap-external-engine-errors.

Lead-authored-by: alekjarmov <[email protected]>
Co-authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants