Skip to content

fix(spark): return NULL from parse_url for a malformed URL unless ANSI - #26344

Open
ozenyunus35 wants to merge 1 commit into
apache:mainfrom
ozenyunus35:spark-parse-url-ansi
Open

ozenyunus35 wants to merge 1 commit into
apache:mainfrom
ozenyunus35:spark-parse-url-ansi

Conversation

@ozenyunus35

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

In Spark, parse_url returns NULL for a malformed URL unless ANSI mode is on, and only then raises INVALID_URL. The datafusion-spark version always raised, and didn't look at datafusion.execution.enable_ansi_mode, so with the default (ANSI off) a query that returns NULL in Spark failed here.

What changes are included in this PR?

  • ParseUrl::invoke_with_args reads enable_ansi_mode from the config, the same way elt does.
  • spark_parse_url turns a parse error into NULL when ANSI mode is off, like try_parse_url does; with ANSI mode on it keeps the current error. Argument count and type errors are not affected.

What is the testing strategy for this PR?

  • parse_url.slt: the malformed URL case from the issue now returns NULL by default and still errors with enable_ansi_mode = true, and the same for a URL with an out-of-range port (InvalidPort). Without the change, the two NULL cases fail.
  • New unit test test_malformed_url_is_null_unless_ansi checks both modes on a batch with a valid and a malformed URL.
  • cargo test -p datafusion-spark --lib url::parse_url, the spark/url sqllogictests and cargo clippy -p datafusion-spark --all-targets -- -D warnings pass.

Are there any user-facing changes?

Yes: with ANSI mode off (the default), parse_url returns NULL for a malformed URL instead of an error, matching Spark.

I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark labels Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spark sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] parse_url raises on a malformed URL when ANSI mode is off, Spark returns NULL

1 participant