Skip to content

fix(spark): parse_url returns NULL for malformed URLs when ANSI is off - #26919

Closed
ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/26341-parse-url-ansi
Closed

ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/26341-parse-url-ansi

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Spark's parse_url treats a malformed URL as an error only when ANSI mode
is enabled (failOnError). With ANSI off (DataFusion's default), Spark
returns NULL instead. Our parse_url always raised, so queries that Spark
would tolerate failed here. try_parse_url already maps parse failures to
NULL; parse_url should do the same whenever ANSI is off.

What changes are included in this PR?

  • ParseUrl::invoke_with_args reads enable_ansi_mode (same pattern as
    elt / round) and passes it into spark_parse_url.
  • When ANSI is off, parse errors become NULL; when on, they still error.
    Wrong arity / non-string args still error either way.
  • Unit test for the ANSI/non-ANSI paths, plus sqllogictest coverage for a
    space-in-scheme URL and an out-of-range port.

What is the testing strategy for this PR?

  • Unit: cargo test -p datafusion-spark --lib function::url::parse_url
  • SQL: cargo test -p datafusion-sqllogictest --test sqllogictests -- spark/url/parse_url

Are there any user-facing changes?

Yes — with the default (enable_ansi_mode = false), parse_url on a
malformed URL now returns NULL instead of an Execution error. Callers that
need the strict behavior can set datafusion.execution.enable_ansi_mode = true
or use try_parse_url when they always want NULL.

AI assistance

Used AI tooling to locate the bug against Spark semantics and draft the
change; I reviewed the patch, ran the tests above, and wrote this description.

Spark's parse_url fails on a bad URL only when ANSI mode (failOnError) is
on; otherwise it returns NULL. Wire enable_ansi_mode into ParseUrl the same
way elt/round do, and map parse errors to NULL when ANSI is disabled.
Argument-count and type errors still fail regardless of ANSI.

Closes apache#26341.
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark Changes to datafusion-spark crate labels Oct 30, 2026
@2010YOUY01

Copy link
Copy Markdown
Member

Closing due to

It's impossible to contribute responsibly in such PR volume, please don't do automated contribution in this project.

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

Labels

spark Changes to datafusion-spark crate 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

2 participants