Skip to content

perf: preserve left functional dependencies for ASOF joins - #24799

Draft
Xuanwo wants to merge 4 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-functional-dependencies
Draft

perf: preserve left functional dependencies for ASOF joins#24799
Xuanwo wants to merge 4 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-functional-dependencies

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Aug 30, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

An ASOF join emits exactly one output row for every left row. Unlike a general
left join, it cannot duplicate left rows, so functional dependencies from the
left input keep their original dependency mode. Dependencies from the right
input are not preserved because one right row may match multiple left rows.

Keeping this metadata lets downstream optimizer rules continue to use left-side
uniqueness after an ASOF join.

GitHub shows the cumulative stack because fork branches cannot be selected as
upstream PR bases. The isolated diff for this layer is:
Xuanwo/datafusion@xuanwo/asof-logical...xuanwo/asof-functional-dependencies

What changes are included in this PR?

  • Preserve the left input's functional dependencies when building the ASOF
    output schema.
  • Document the one-output-row-per-left-row assumption at the ownership boundary.
  • Add a focused test that preserves a left Single dependency and rejects
    propagation of the corresponding right dependency.

Are these changes tested?

  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test -p datafusion-expr asof_join_schema_preserves_only_left_dependencies --all-features
  • The extended workspace test command from the contributor guide

Are there any user-facing changes?

No result semantics or public APIs change. This only improves optimizer metadata
for logical ASOF joins.

@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate substrait Changes to the substrait crate proto Related to proto crate physical-plan Changes to the physical-plan crate labels Aug 30, 2026
@github-actions

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 v55.0.0 (current)
       Built [  49.499s] (current)
     Parsing datafusion v55.0.0 (current)
      Parsed [   0.029s] (current)
    Building datafusion v55.0.0 (baseline)
       Built [  49.284s] (baseline)
     Parsing datafusion v55.0.0 (baseline)
      Parsed [   0.029s] (baseline)
    Checking datafusion v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.774s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 102.075s] datafusion
    Building datafusion-expr v55.0.0 (current)
       Built [  24.081s] (current)
     Parsing datafusion-expr v55.0.0 (current)
      Parsed [   0.064s] (current)
    Building datafusion-expr v55.0.0 (baseline)
       Built [  24.133s] (baseline)
     Parsing datafusion-expr v55.0.0 (baseline)
      Parsed [   0.064s] (baseline)
    Checking datafusion-expr v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   1.562s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/enum_variant_added.ron

Failed in:
  variant LogicalPlan:AsOfJoin in /home/runner/work/datafusion/datafusion/datafusion/expr/src/logical_plan/plan.rs:301
  variant LogicalPlan:AsOfJoin in /home/runner/work/datafusion/datafusion/datafusion/expr/src/logical_plan/plan.rs:301

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  51.286s] datafusion-expr
    Building datafusion-optimizer v55.0.0 (current)
       Built [  23.617s] (current)
     Parsing datafusion-optimizer v55.0.0 (current)
      Parsed [   0.026s] (current)
    Building datafusion-optimizer v55.0.0 (baseline)
       Built [  23.109s] (baseline)
     Parsing datafusion-optimizer v55.0.0 (baseline)
      Parsed [   0.027s] (baseline)
    Checking datafusion-optimizer v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.198s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  47.943s] datafusion-optimizer
    Building datafusion-physical-plan v55.0.0 (current)
       Built [  32.426s] (current)
     Parsing datafusion-physical-plan v55.0.0 (current)
      Parsed [   0.126s] (current)
    Building datafusion-physical-plan v55.0.0 (baseline)
       Built [  31.927s] (baseline)
     Parsing datafusion-physical-plan v55.0.0 (baseline)
      Parsed [   0.127s] (baseline)
    Checking datafusion-physical-plan v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.863s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  66.795s] datafusion-physical-plan
    Building datafusion-proto v55.0.0 (current)
       Built [  46.269s] (current)
     Parsing datafusion-proto v55.0.0 (current)
      Parsed [   0.015s] (current)
    Building datafusion-proto v55.0.0 (baseline)
       Built [  45.803s] (baseline)
     Parsing datafusion-proto v55.0.0 (baseline)
      Parsed [   0.016s] (baseline)
    Checking datafusion-proto v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.145s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  94.000s] datafusion-proto
    Building datafusion-sql v55.0.0 (current)
       Built [  35.882s] (current)
     Parsing datafusion-sql v55.0.0 (current)
      Parsed [   0.027s] (current)
    Building datafusion-sql v55.0.0 (baseline)
       Built [  35.638s] (baseline)
     Parsing datafusion-sql v55.0.0 (baseline)
      Parsed [   0.028s] (baseline)
    Checking datafusion-sql v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.277s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  73.042s] datafusion-sql
    Building datafusion-substrait v55.0.0 (current)
       Built [ 253.210s] (current)
     Parsing datafusion-substrait v55.0.0 (current)
      Parsed [   0.018s] (current)
    Building datafusion-substrait v55.0.0 (baseline)
       Built [ 255.345s] (baseline)
     Parsing datafusion-substrait v55.0.0 (baseline)
      Parsed [   0.015s] (baseline)
    Checking datafusion-substrait v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.279s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 510.975s] datafusion-substrait

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Aug 30, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.66093% with 270 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.48%. Comparing base (c4910e0) to head (dc29f28).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/expr/src/logical_plan/plan.rs 40.51% 101 Missing and 15 partials ⚠️
datafusion/expr/src/logical_plan/tree_node.rs 0.00% 43 Missing ⚠️
datafusion/core/src/physical_planner.rs 0.00% 41 Missing ⚠️
datafusion/expr/src/logical_plan/builder.rs 66.66% 21 Missing and 7 partials ⚠️
datafusion/optimizer/src/analyzer/type_coercion.rs 0.00% 28 Missing ⚠️
datafusion/expr/src/logical_plan/display.rs 0.00% 10 Missing ⚠️
datafusion/optimizer/src/optimizer.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main   #24799     +/-   ##
=========================================
  Coverage   81.47%   81.48%             
=========================================
  Files        1122     1123      +1     
  Lines      403629   406506   +2877     
  Branches   403629   406506   +2877     
=========================================
+ Hits       328866   331239   +2373     
- Misses      55510    55880    +370     
- Partials    19253    19387    +134     

☔ 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.

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 core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules physical-plan Changes to the physical-plan crate proto Related to proto crate sql SQL Planner substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants