feat: support floating-point ASOF equality keys - #24375
Conversation
|
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24375 +/- ##
==========================================
+ Coverage 81.31% 81.36% +0.05%
==========================================
Files 1117 1119 +2
Lines 395987 398916 +2929
Branches 395987 398916 +2929
==========================================
+ Hits 321993 324593 +2600
- Misses 55177 55332 +155
- Partials 18817 18991 +174 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
## Which issue does this PR close? - Part of #318. - Umbrella PR: apache#23738. - Follow-up for floating-point equality keys: apache#24375. ## Rationale for this change This is the first layer of the ASOF JOIN stack. It establishes a broadcast-based physical execution contract independently so later floating-point equality, logical-plan, SQL, DataFrame, and serialization changes can be reviewed as smaller follow-up PRs. The initial implementation deliberately favors the simpler broadcast design: the right input must fit in memory and each left partition scans the shared right-side batches. A repartitioned implementation can be evaluated separately without changing the ASOF semantics introduced here. Floating-point equality keys are rejected in this base layer because Arrow's required sort order distinguishes `-0.0` from `+0.0` while join equality does not. apache#24375 adds the required ordering normalization as an independently reviewable layer. ## What changes are included in this PR? - Add `AsOfJoinExec` for left-preserving, Snowflake-style ASOF semantics. - Coalesce and collect the ordered right input once, then share it across all left partitions. - Keep the left input partitioned so each partition can scan independently and preserve the left-side output partitioning. - Preserve merge state across input and output batch boundaries. - Reserve each retained Arrow buffer exactly once, including when right-side batches are zero-copy slices, and expose build, match, and output metrics. - Define output properties and statistics for the broadcast execution model. - Reject floating-point equality keys until apache#24375 supplies a sort/equality contract that handles signed zero correctly. - Add physical operator tests covering match directions, equality groups, batch boundaries, unmatched rows, invalid contracts, shared-buffer memory accounting, multi-partition broadcast execution, and float-key rejection. ## Are these changes tested? Yes: - `cargo fmt --all` - `cargo clippy --all-targets --all-features -- -D warnings` - `cargo test -p datafusion-physical-plan joins::asof_join --all-features` - Extended workspace tests from the contributor guide - FFI integration tests ## Are there any user-facing changes? This adds a new physical operator API. The base operator deliberately rejects floating-point equality keys; apache#24375 adds full Float16, Float32, and Float64 support. SQL and DataFrame APIs are left to later dependent PRs. --------- Co-authored-by: Yongting You <2010youy01@gmail.com>
6b0bd0e to
8f501fd
Compare
|
cc @2010YOUY01, this PR is now ready for review! |
| /// order-preserving but not strictly order-preserving because it collapses the | ||
| /// two signed-zero representations. | ||
| #[derive(Debug, Eq)] | ||
| pub struct NormalizeFloatZeroExpr { |
There was a problem hiding this comment.
I still have a question about why we introduce another PhysicalExpr to handle this type issue instead of just calling normalize_float_zero.
There was a problem hiding this comment.
Good question. normalize_float_zero works on an already evaluated array, but here normalization must be part of the required ordering.
For example, raw [key, ts] may be (-0, 10), (+0, 1). Normalizing only during comparison makes them one equality group but leaves ts as [10, 1], breaking the forward scan. We need the input sorted by [normalize_float_zero(key), ts].
The new PhysicalExpr is the plan-level wrapper around the existing helper, allowing SortExec, ordering enforcement, and protobuf to represent this without changing float sorting globally.
Let me know if this addressed your concerns. I'm open to better ideas!
There was a problem hiding this comment.
I'll take a look at this. My read is that it's handling the edge cases for asof join.
One thing I'm worried about: we'd end up with NormalizeFloatZeroExpr and normalize_float_zero spread across a lot of call sites, which seems likely to cause confusion down the line.
Would it make sense to land a minimal PR first — just enough to get a simple asof join working — and then iterate on the other cases after that? What do you think?
There was a problem hiding this comment.
Yep, only ASOF join use this part of logic. I'm open to leave it as a follow-up. I'll adjust the stack and get it a out so that we can work on ASOF join first.
Which issue does this PR close?
Rationale for this change
The physical ASOF operator in #23828 rejects floating-point equality keys because
Arrow's total ordering distinguishes
-0.0from+0.0, while join equalitytreats them as equal. That mismatch can split one equality group during the
required input sort and make the forward-only ASOF scan choose the wrong row.
This PR adds complete Float16, Float32, and Float64 equality-key support as an
independent follow-up. The logical, SQL, DataFrame, serialization, and benchmark
PRs in #23738 do not depend on it and can merge first while floating equality
keys remain rejected during physical planning.
#23828 is merged, so this PR's diff against
mainis the isolatedfloating-point equality layer.
What changes are included in this PR?
NormalizeFloatZeroExprthat maps-0.0to+0.0without changing other values.required sort order agrees with the existing join-key comparator.
expression round-trip correctly.
(-0.0, ts=10)followed by(+0.0, ts=1)must remain one group and selectts=1for a left(+0.0, ts=5)row.Are these changes tested?
Yes:
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningsAre there any user-facing changes?
ASOF equality keys can use Float16, Float32, and Float64 while treating signed
zero consistently with join equality. This layer also adds a public physical
expression and an append-only protobuf oneof variant; existing wire tags are not
reused.