Skip to content

fix: preserve outer join equivalences for null rows - #26042

Open
Prajwal-k-tech wants to merge 2 commits into
apache:mainfrom
Prajwal-k-tech:prajwal/26036-outer-join-equivalence
Open

Prajwal-k-tech wants to merge 2 commits into
apache:mainfrom
Prajwal-k-tech:prajwal/26036-outer-join-equivalence

Conversation

@Prajwal-k-tech

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

After a LEFT, RIGHT, or FULL OUTER JOIN, the nullable side can contain rows whose columns were extended with NULLs. An equivalence such as b = coalesce(a, 0) is true on the input rows but does not remain true for those null-extended rows. Retaining it can lead to incorrect ordering and LIMIT results.

What changes are included in this PR?

  • Filter nullable-side equivalence classes against a one-row all-NULL batch for the outer-join cases where that side may be null-extended.
  • Ignore volatile expressions during this check and discard classes that are no longer meaningful.
  • Add LEFT and FULL OUTER JOIN SQL regression cases, including the reported ORDER BY/LIMIT behavior.

What is the testing strategy for this PR?

  • Verified the new SQL cases fail on the unmodified code and pass with this change.
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- joins
  • cargo test -p datafusion-physical-expr (1,685 passed, 2 ignored; 13 doctests passed)
  • RUST_BACKTRACE=1 cargo test -p datafusion (passed)
  • RUST_BACKTRACE=1 cargo test -p datafusion-cli (passed)
  • cargo clippy --all-targets --all-features -- -D warnings (passed)
  • cargo +1.99.0 fmt --all -- --check and git diff --check (passed)

This contribution was prepared with AI assistance.

Are there any user-facing changes?

This fixes incorrect query results for affected outer joins. There are no API changes.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 22:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-physical-expr v55.1.0 (current)
       Built [  29.470s] (current)
     Parsing datafusion-physical-expr v55.1.0 (current)
      Parsed [   0.049s] (current)
    Building datafusion-physical-expr v55.1.0 (baseline)
       Built [  28.554s] (baseline)
     Parsing datafusion-physical-expr v55.1.0 (baseline)
      Parsed [   0.051s] (baseline)
    Checking datafusion-physical-expr v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.349s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip

--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters, not counting the receiver (self) parameter.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/method_parameter_count_changed.ron

Failed in:
  datafusion_physical_expr::equivalence::EquivalenceGroup::join takes 4 parameters in /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/705d2e66e6058a9682221d3e6bffabc69ba10efe/datafusion/physical-expr/src/equivalence/class.rs:812, but now takes 5 parameters in /home/runner/work/datafusion/datafusion/datafusion/physical-expr/src/equivalence/class.rs:816

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  59.637s] datafusion-physical-expr
    Building datafusion-sqllogictest v55.1.0 (current)
       Built [  96.372s] (current)
     Parsing datafusion-sqllogictest v55.1.0 (current)
      Parsed [   0.016s] (current)
    Building datafusion-sqllogictest v55.1.0 (baseline)
       Built [  96.396s] (baseline)
     Parsing datafusion-sqllogictest v55.1.0 (baseline)
      Parsed [   0.018s] (baseline)
    Checking datafusion-sqllogictest v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.112s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 196.784s] datafusion-sqllogictest

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Oct 4, 2026
@Prajwal-k-tech

Copy link
Copy Markdown
Author

I pushed a regression fix for the CI failure: zero-column batches now preserve their row count, with a focused Full-join test. GitHub marked the new fork workflow runs as action_required before starting jobs. Could a maintainer approve them so CI can verify the updated commit?

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

Labels

auto detected api change Auto detected API change physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong ORDER BY results after an outer join when the nullable side equates a column to coalesce/CASE

2 participants