Skip to content

feat: support ASOF JOIN SQL - #23830

Open
Xuanwo wants to merge 8 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-sql
Open

feat: support ASOF JOIN SQL#23830
Xuanwo wants to merge 8 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-sql

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Jul 23, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

This is the SQL frontend layer of the ASOF JOIN stack. It adds syntax and
unparsing on top of the merged physical and logical contracts. The PR now
contains only the isolated SQL frontend diff.

What changes are included in this PR?

  • Plan ASOF JOIN ... MATCH_CONDITION (...) with optional ON or USING
    equality keys.
  • Reject unsupported match shapes and non-equality ON predicates.
  • Unparse ASOF joins while preserving right-side candidate preselection and
    nested join scope.
  • Document the supported SQL syntax and semantics, including qualified
    USING keys, left-partitioned broadcast execution, the full-right memory
    requirement, repeated scans, and the absence of spill/repartitioned ASOF.
  • Add SQL integration and sqllogictest coverage for all four match directions,
    coercion, equality-free joins, USING, invalid contracts, EXPLAIN, boundedness,
    and optimized-plan round trips.
  • Verify the broadcast topology with a multi-partition left input: left
    partitioning is preserved while the right input is single-partitioned.

Are these changes tested?

Yes:

  • cargo fmt --all
  • ./ci/scripts/doc_prettier_check.sh --write --allow-dirty
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test -p datafusion --test core_integration asof --all-features
  • cargo test -p datafusion-sqllogictest --test sqllogictests --all-features -- asof_join
  • The extended workspace test command from the contributor guide

Are there any user-facing changes?

Users can express Snowflake-style ASOF joins in SQL with
MATCH_CONDITION, optional equality keys, and <, <=, >, or >= match
directions. With USING, wildcard output exposes one unqualified key while
both qualified input keys remain addressable. The user guide also documents
the initial broadcast strategy and its memory/no-spill limitations.

#23829 and #23828 are merged. This is the next core layer in the ASOF stack and
does not depend on the optional floating-point follow-up #24375.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sql SQL Planner logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) substrait Changes to the substrait crate proto Related to proto crate physical-plan Changes to the physical-plan crate labels Jul 23, 2026
@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.45570% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.62%. Comparing base (9fc7a4d) to head (56e3ec7).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/sql/src/unparser/plan.rs 51.16% 77 Missing and 7 partials ⚠️
datafusion/sql/src/relation/join.rs 77.35% 5 Missing and 7 partials ⚠️
datafusion/expr/src/logical_plan/builder.rs 87.80% 3 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23830      +/-   ##
==========================================
+ Coverage   81.57%   81.62%   +0.04%     
==========================================
  Files        1123     1123              
  Lines      410789   411095     +306     
  Branches   410789   411095     +306     
==========================================
+ Hits       335120   335536     +416     
+ Misses      55913    55770     -143     
- Partials    19756    19789      +33     

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

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Jul 23, 2026
@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Aug 14, 2026
@github-actions github-actions Bot removed physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Aug 28, 2026
@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Aug 30, 2026
# Conflicts:
#	datafusion/expr/src/logical_plan/builder.rs
#	datafusion/expr/src/logical_plan/plan.rs
@github-actions github-actions Bot removed optimizer Optimizer rules substrait Changes to the substrait crate labels Sep 4, 2026
@github-actions github-actions Bot removed proto Related to proto crate physical-plan Changes to the physical-plan crate labels Sep 4, 2026
@Xuanwo
Xuanwo marked this pull request as ready for review September 4, 2026 03:47
@Xuanwo

Xuanwo commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

cc @2010YOUY01, this PR is good to go! 🚀

Also CC @jayzhan211: would you like to follow this stack's review? Happy to ping you if you're interested. 😄

@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Sep 4, 2026
@jayzhan211

Copy link
Copy Markdown
Contributor

cc @2010YOUY01, this PR is good to go! 🚀

Also CC @jayzhan211: would you like to follow this stack's review? Happy to ping you if you're interested. 😄

Of course!

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

Thanks @Xuanwo Minor issues left, others LGTM

let already_projected = select.already_projected();
let left_plan =
Self::unwrap_qualified_passthrough_join_projection(Arc::clone(&join.left));
let inline_left_join = matches!(left_plan.as_ref(), LogicalPlan::Join(_));

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.

Do we need asof join here

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.

Same with unwrap_qualified_passthrough_join_projection

return Ok(None);
let join_plan = match plan {
LogicalPlan::Join(_) => plan,
LogicalPlan::Projection(projection)

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.

Do we need asof join

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

Labels

core Core DataFusion crate documentation Improvements or additions to documentation logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants