refactor(asof_join): enhance match value handling and comparator caching - #24519
Conversation
|
@2010YOUY01 @Xuanwo Could you review this when you have a moment? Thanks! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24519 +/- ##
=======================================
Coverage 81.52% 81.52%
=======================================
Files 1123 1123
Lines 405970 406041 +71
Branches 405970 406041 +71
=======================================
+ Hits 330978 331040 +62
- Misses 55627 55636 +9
Partials 19365 19365 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thank you! This PR does 1) perf 2) fix float +0.0 and -0.0 normalization, right? I have some thoughts on the zero normalization part: Is it possible to add an optimizer rule, to rewrite the expression like Other implementations seem can also benefit: #22835 |
I have concerns for moving this out as optimizer rule
|
|
I see, this makes sense to me. One extra challenge is how should we keep the +- 0.0 handling consistent in the entire project, and make this approach documented somewhere, otherwise different implementations will handle it differently #22835 Regarding the optimization part, I suggest we can wait until SQL and benchmark is done for #23738. Though this PR should be strictly better in performance, but we might be able to find some more aggressive optimization that need to structure the code differently, and it's easier to review when the benchmark is ready. Ideally we can proceed with a smaller fix-only PR right now, maybe #24375 from @Xuanwo |
Xuanwo
left a comment
There was a problem hiding this comment.
The perf part looks good to me!
|
#24375 looks overkill for me.
Another idea that came to mind is to make this a trait method on ExecutionPlan, so whether to apply this conversion can be configurable. |
|
For the performance part, since ASOF is not yet complete, I don’t think a benchmark is a hard requirement. If it looks good to you guys, we can move forward with this first. Let me split that part into another PR and leave the normalize_neg_zero discussion for later. |
Yes, just a suggestion, not a hard requirement. It should be good to go if others can review, I might not be able to get to it timely. |
Thanks for the heads-up! That sounds good to me. I’ll ask others to take a look as well, and no worries if you don’t get a chance to review it in time. @alamb Could you take a look when you have a chance? This also looks good to @Xuanwo. I think we can merge it without a benchmark, similar to what we did for the physical operator in #23828, and continue iterating on it afterward. |
alamb
left a comment
There was a problem hiding this comment.
Looks reasonable to me -- thanks @jayzhan211 and @Xuanwo
|
@kosiew Your comment in #24607 makes a good point — the negative zero case should be resolved together with the comparator. Here's what I'm planning:
|
Rationale for this change
ASOF joins currently convert both match values into
ScalarValues for row-levelcomparisons. This adds repeated scalar construction and type dispatch to the
ordered scan hot path.
The match expressions are already evaluated into Arrow arrays for each input
batch, so the join can compare array positions directly using an Arrow
comparator constructed once per left/right batch pair.
What changes are included in this PR?
materialization.
preserve SQL semantics where
-0.0and+0.0compare equal.buffers, and forward-only scanning are important to the hot path.
Are these changes tested?
Yes.
-0.0and+0.0remain equal for ASOF match conditions.
comparison directions, shared build memory, and expression validation.
The following checks pass:
cargo test -p datafusion-physical-plan asof_join --libcargo clippy -p datafusion-physical-plan --lib -- -D warningscargo fmt --all -- --checkAre there any user-facing changes?
No API or query-semantic changes are intended.
This is an internal execution optimization. Floating-point signed-zero and
logical-NULL behavior are explicitly preserved.