Skip to content

fix: preserve compound expression equivalences through projection - #25922

Merged
kumarUjjawal merged 1 commit into
apache:mainfrom
aaron-perpetual:fix/preserve-projected-equivalences
Oct 2, 2026
Merged

kumarUjjawal merged 1 commit into
apache:mainfrom
aaron-perpetual:fix/preserve-projected-equivalences

Conversation

@aaron-perpetual

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Valid queries that sort by a struct field after a left join can fail physical plan validation because a projection loses the equivalence between the field access and an extracted column.

What changes are included in this PR?

Reorder EquivalenceGroup::project_expr_indirect to reconstruct an expression from its projected children before substituting an equivalent expression. This preserves equivalences such as get_field(n, 'label') = extracted_label when both representations survive the projection.

What is the testing strategy for this PR?

Add SQL regression tests in joins.slt covering a left join followed by sorting on a struct field, both with and without an explicitly projected scalar alias. The tests use two partitions to exercise the local sort and sort-preserving merge, and verify the ordered results.

The extended workspace tests, physical expression tests, and full lint suite pass.

Are there any user-facing changes?

Affected queries now execute successfully instead of failing physical plan validation. No public API changes.

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

@kumarUjjawal kumarUjjawal 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.

Thank you @aaron-perpetual for the fix.

Looks good 👍

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.60%. Comparing base (6924c6a) to head (ab8500c).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #25922    +/-   ##
========================================
  Coverage   82.60%   82.60%            
========================================
  Files        1144     1144            
  Lines      442793   442905   +112     
  Branches   442793   442905   +112     
========================================
+ Hits       365779   365874    +95     
- Misses      54863    54875    +12     
- Partials    22151    22156     +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kumarUjjawal
kumarUjjawal added this pull request to the merge queue Oct 2, 2026
Merged via the queue into apache:main with commit e6dfef5 Oct 2, 2026
42 checks passed
Omega359 pushed a commit to Omega359/arrow-datafusion that referenced this pull request Oct 11, 2026
…ache#25922)

## Which issue does this PR close?

- Closes apache#25921.

## Rationale for this change

Valid queries that sort by a struct field after a left join can fail
physical plan validation because a projection loses the equivalence
between the field access and an extracted column.

## What changes are included in this PR?

Reorder `EquivalenceGroup::project_expr_indirect` to reconstruct an
expression from its projected children before substituting an equivalent
expression. This preserves equivalences such as `get_field(n, 'label') =
extracted_label` when both representations survive the projection.

## What is the testing strategy for this PR?

Add SQL regression tests in `joins.slt` covering a left join followed by
sorting on a struct field, both with and without an explicitly projected
scalar alias. The tests use two partitions to exercise the local sort
and sort-preserving merge, and verify the ordered results.

The extended workspace tests, physical expression tests, and full lint
suite pass.

## Are there any user-facing changes?

Affected queries now execute successfully instead of failing physical
plan validation. No public API changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LEFT JOIN with struct-field ORDER BY fails ordering validation

3 participants