mohammadnaqvi04 opened a new pull request, #26904:
URL: https://github.com/apache/datafusion/pull/26904
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Part of #5492.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
Please explain the problem you are trying to solve in terms of the
user-visible
behavior, rather than the implementation.
For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the
implementation. "COUNT(DISTINCT) returns wrong results when the column
contains
nulls" is the user-visible problem.
-->
Many correlated subqueries fail to plan in DataFusion today, and some return
wrong rows. #5492 tracks a general decorrelation rule to replace the current
rules, and the plan proposed there starts with a tests-only PR, so every later
PR has a fixed set of queries to check its fixes against.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here, but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
`subquery_decorrelation.slt` containing 57 queries.
Includes the following:
- The 12 shapes of the shape catalog linked in
[#5492](https://github.com/apache/datafusion/issues/5492#issuecomment-5934476405).
Three fail at planning with a schema error, six are left in the plan and fail
at physical planning, one is a control that works today, and two are not valid
SQL, because an aggregate over outer columns only belongs to the outer query.
DuckDB rejects those two, and DataFusion should reject them while planning.
- All 44 queries from the repros in @jayzhan211's prototype branch, mostly
one per issue, including the dbolympics shapes
([#26704](https://github.com/apache/datafusion/issues/26704),
[#26710](https://github.com/apache/datafusion/issues/26710),
[#14554](https://github.com/apache/datafusion/issues/14554),
[#16137](https://github.com/apache/datafusion/issues/16137),
[#15558](https://github.com/apache/datafusion/issues/15558)) and the
wrong-result issues
([#26014](https://github.com/apache/datafusion/issues/26014),
[#26032](https://github.com/apache/datafusion/issues/26032),
[#25808](https://github.com/apache/datafusion/issues/25808),
[#26503](https://github.com/apache/datafusion/issues/26503),
[#26692](https://github.com/apache/datafusion/issues/26692)). The
[#26285](https://github.com/apache/datafusion/issues/26285) query panics in the
hash join today, so it runs with `datafusion.optimizer.prefer_hash_join =
false`, which gives the error from the issue instead.
- The repro for [#26572](https://github.com/apache/datafusion/issues/26572)
from the list on
[#5492](https://github.com/apache/datafusion/issues/5492#issuecomment-6479109212).
[#26569](https://github.com/apache/datafusion/issues/26569) from that list
isn't included, because it only affects joins built through the Rust API.
DataFusion's own decorrelation sets the value key count
(`null_aware(value_keys=2)` for a two-column `NOT IN`), so no SQL query shows
it.
The cases @jayzhan211's fuzzer found will follow in a second PR.
Each query records what `main` returns today, so a PR that fixes one
replaces the recorded error or rows with the right answer. Cases taken from an
issue link to it. Today the 57 queries break down as follows.
| Today | Queries |
|---|---|
| Fails to plan or execute | 34 |
| Returns wrong rows | 11 |
| Returns the right rows | 8 |
| Fails, as it should | 4 |
## What is the testing strategy for this PR?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
Briefly describe how this PR is tested, and point to the specific tests you
added. For example: 'This new feature is covered by the `sqllogictest` cases
added in `foo.slt`'.
If this PR does not add tests, explain why. For example, if the change is
already covered by existing tests, please mention it.
You should also check the `codecov` bot reply on this PR to confirm the
changed code is exercised.
-->
The file passes on `main`, with output recorded by `--complete`, errors
trimmed to stable patterns, and `rowsort` for queries without an `ORDER BY`.
Answers were checked against DuckDB 2.0.0, and SQLite 3.51 agrees on 51 of the
57. @jayzhan211's harness agrees with the file on the 40 of 44 repro queries it
can check.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No, this only adds tests.
## AI Usage
_AI was used during development of this PR, primarily to help review the
test suite and verify test cases against the DB binaries._
--
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]