Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SPARK-59476][SQL] Throw NULL_DATA_SOURCE_OPTION for null JDBC url instead of NullPointerException - #58766

Open
dejankrak-db wants to merge 1 commit into
apache:masterfrom
dejankrak-db:jdbc-null-url-guard
Open

[SPARK-59476][SQL] Throw NULL_DATA_SOURCE_OPTION for null JDBC url instead of NullPointerException#58766
dejankrak-db wants to merge 1 commit into
apache:masterfrom
dejankrak-db:jdbc-null-url-guard

Conversation

@dejankrak-db

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

A JDBC read with a null url option satisfies the presence check
require(parameters.isDefinedAt(JDBC_URL), ...) in JDBCOptions (the key is
present), but the value itself is null. That null then flows into
DriverManager.getDriver(url), which throws a raw NullPointerException
surfacing to the user as an opaque INTERNAL_ERROR.

This PR guards the null value right after it is read in JDBCOptions and throws
the user-facing NULL_DATA_SOURCE_OPTION error instead, mirroring the existing
null-value guard already present in JDBCOptions.asProperties.

Why are the changes needed?

A null option value is a user input error, not an internal Spark failure. It
should be reported with the actionable NULL_DATA_SOURCE_OPTION error class
(pointing at the url option) rather than a NullPointerException /
INTERNAL_ERROR, which is confusing and looks like a Spark bug.

Does this PR introduce any user-facing change?

Yes. Constructing a JDBC relation with a null url option now fails with the
NULL_DATA_SOURCE_OPTION error (a SparkIllegalArgumentException) instead of a
NullPointerException surfaced as INTERNAL_ERROR. No change for valid inputs.

How was this patch tested?

Added a unit test in JdbcUtilsSuite that constructs JDBCOptions with a null
url and asserts the NULL_DATA_SOURCE_OPTION error is raised with the
expected option parameter.

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

Generated-by: Isaac

This pull request and its description were written by Isaac.

…stead of NullPointerException

A JDBC read with a null `url` option satisfied the presence check
(`parameters.isDefinedAt(JDBC_URL)`) but produced a null value, so
`DriverManager.getDriver(null)` threw a raw NullPointerException that
surfaced as INTERNAL_ERROR. Guard the null url in JDBCOptions and throw
the user-facing NULL_DATA_SOURCE_OPTION error, mirroring the existing
null-value guard in `asProperties`.

Co-authored-by: Isaac <[email protected]>

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @dejankrak-db and @HyukjinKwon!

// `isDefinedAt` above only checks the key is present; the value can still be `null`. Guard it
// here so a null url surfaces as a user-facing error instead of a raw NullPointerException from
// `DriverManager.getDriver(url)` below. Mirrors the null-value guard in `asProperties`.
if (url == null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dejankrak-db Could you just please check whether this is reachable:

The new url == null check never runs. asProperties is initialized first (SPARK-48601) and already throws NULL_DATA_SOURCE_OPTION for every null option, including url. The new test should pass on master without the JDBCOptions change.

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes just to prevent accidental merge until we verify the behaviour. Please see comments above.

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.

3 participants