1fanwang opened a new pull request, #25742: URL: https://github.com/apache/datafusion/pull/25742
## Which issue does this PR close? - Closes #12955 - Closes #12956 ## Rationale for this change `INTERSECT ALL` and `EXCEPT ALL` currently treat matching rows as sets rather than bags. As a result, `INTERSECT ALL` can return too many duplicates and `EXCEPT ALL` can remove too many rows. NULL values must also match according to set-operation semantics. ## What changes are included in this PR? The planner assigns `row_number()` within each set-operation key on both inputs, then joins on the original columns and row number. This preserves the minimum count for `INTERSECT ALL` and the remaining left-side count for `EXCEPT ALL`, while using NULL-safe equality. ## What is the testing strategy for this PR? Added SQL execution regressions covering duplicate counts and NULL values for both `INTERSECT ALL` and `EXCEPT ALL`. The targeted SQL integration tests pass. <details> <summary>Raw SQL verification</summary> ```console # Base ref (696eaf58d) $ printf 'SELECT * FROM VALUES (1), (1), (2), (2), (3) INTERSECT ALL SELECT * FROM VALUES (1), (1), (1), (2), (4);\nSELECT * FROM VALUES (1), (1), (2), (2), (3) EXCEPT ALL SELECT * FROM VALUES (1), (1), (1), (2), (4);\n' | datafusion-cli DataFusion CLI v55.1.0 +---------+ | column1 | +---------+ | 1 | | 1 | | 2 | | 2 | +---------+ 4 row(s) fetched. +---------+ | column1 | +---------+ | 3 | +---------+ 1 row(s) fetched. # PR ref $ printf 'SELECT * FROM VALUES (1), (1), (2), (2), (3) INTERSECT ALL SELECT * FROM VALUES (1), (1), (1), (2), (4);\nSELECT * FROM VALUES (1), (1), (2), (2), (3) EXCEPT ALL SELECT * FROM VALUES (1), (1), (1), (2), (4);\n' | datafusion-cli DataFusion CLI v55.1.0 +---------+ | column1 | +---------+ | 1 | | 1 | | 2 | +---------+ 3 row(s) fetched. +---------+ | column1 | +---------+ | 2 | | 3 | +---------+ 2 row(s) fetched. # Base ref (696eaf58d) $ printf 'SELECT * FROM VALUES (NULL), (NULL), (1) INTERSECT ALL SELECT * FROM VALUES (NULL), (1);\nSELECT * FROM VALUES (NULL), (NULL), (1) EXCEPT ALL SELECT * FROM VALUES (NULL), (1);\n' | datafusion-cli DataFusion CLI v55.1.0 +---------+ | column1 | +---------+ | NULL | | NULL | | 1 | +---------+ 3 row(s) fetched. +---------+ | column1 | +---------+ 0 row(s) fetched. # PR ref $ printf 'SELECT * FROM VALUES (NULL), (NULL), (1) INTERSECT ALL SELECT * FROM VALUES (NULL), (1);\nSELECT * FROM VALUES (NULL), (NULL), (1) EXCEPT ALL SELECT * FROM VALUES (NULL), (1);\n' | datafusion-cli DataFusion CLI v55.1.0 +---------+ | column1 | +---------+ | 1 | | NULL | +---------+ 2 row(s) fetched. +---------+ | column1 | +---------+ | NULL | +---------+ 1 row(s) fetched. ``` </details> `cargo fmt --all`, Clippy, and the Rust checks in `./dev/rust_lint.sh` pass. The lint suite's documentation prettier check cannot run because `npx` is unavailable. The extended workspace test command is blocked by the checkout's missing `testing/data` submodule. ## Are there any user-facing changes? Yes. `INTERSECT ALL` and `EXCEPT ALL` now return the correct duplicate counts, including for NULL values. -- 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]
