Aryan2210 opened a new pull request, #432:
URL: https://github.com/apache/datafusion-spark/pull/432
## Which issue does this PR close?
- Closes #409.
## Rationale for this change
With a third `key` argument,
`parse_url('http://spark.apache.org/path?query=1', 'HOST', 'query')` returned
`spark.apache.org`, where Spark returns `NULL`. Spark only uses the key with
`QUERY` and returns `NULL` for every other part. `try_parse_url` had the same
problem.
## What changes are included in this PR?
An early return in `ParseUrl::parse` when a key is given and the part is not
`QUERY`. As in Spark, this check comes before the URL is parsed, so an invalid
URL with a key and a non-`QUERY` part returns `NULL` instead of an error, even
in ANSI mode (as requested on the issue). `try_parse_url` goes through the same
function, so it is fixed too.
## Are these changes tested?
Yes, with new cases in `url/parse_url.slt` and `url/try_parse_url.slt`:
every non-`QUERY` part with a key, absolute and schemeless URLs, scalar and
column inputs, and an invalid URL in ANSI mode (`NULL` for `HOST`, still an
error for `QUERY`). The new cases fail without the fix. The full sqllogictest
suite, `cargo test -p datafusion-spark --all-features`, `cargo clippy
--all-targets --all-features --workspace -- -D warnings` and `cargo fmt
--check` pass.
Expected results were checked on Spark 4.2.0 with the PySpark runner
(`crates/sqllogictest/scripts/pyspark_slt_runner.py`): all records in both
files match, apart from the two existing `xfail` records. The Spark source
agrees: Spark 4.2.0 returns `null` before parsing when the part is not `QUERY`
([`UrlExpressionEvalUtils.scala`
L77](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/url/UrlExpressionEvalUtils.scala#L77)),
and Spark 3.5.8 has the same check ([`urlExpressions.scala`
L279](https://github.com/apache/spark/blob/v3.5.8/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/urlExpressions.scala#L279)).
This change also applies cleanly on top of #390, with the `parse_url` tests
passing.
## Are there any user-facing changes?
Yes: `parse_url` and `try_parse_url` with a key now return `NULL` for parts
other than `QUERY`, matching Spark. No API changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]