refactor: Refactor numeric sign and padding in Spark format_string - #24115
refactor: Refactor numeric sign and padding in Spark format_string#24115JSOD11 wants to merge 3 commits into
Conversation
0f5b352 to
1028dfe
Compare
|
cc @kosiew let me know your thoughts |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24115 +/- ##
==========================================
+ Coverage 80.91% 81.02% +0.10%
==========================================
Files 1103 1105 +2
Lines 377219 379692 +2473
Branches 377219 379692 +2473
==========================================
+ Hits 305244 307654 +2410
- Misses 53775 53814 +39
- Partials 18200 18224 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kosiew
left a comment
There was a problem hiding this comment.
Thanks for the cleanup here. Pulling the shared prefix, number, suffix assembly into a single helper makes the formatting logic much easier to follow and reduces the chance of these paths drifting apart again. I also like that the finite-only zero padding behavior for floats is preserved explicitly through the helper.
I have one small suggestion around regression coverage, but nothing that should block this PR. Nice work!
| } | ||
| } | ||
|
|
||
| fn write_numeric_parts( |
There was a problem hiding this comment.
Nice extraction. One thing I'd consider adding is a couple of focused regression tests around the helper's policy boundaries.
In particular, it would be good to verify that %0...f formats NaN and Infinity using space padding rather than zero padding, and that a negative decimal formatted with (, 0, and a width still keeps the closing ) after the digits.
The existing tests cover finite zero padding and parenthesized decimals independently, but these combinations exercise the behavior that write_numeric_parts is now responsible for.
There was a problem hiding this comment.
Thanks for the review!
Good idea, just added these tests. Let me know if the change looks like what you had in mind.
Which issue does this PR close?
Rationale for this change
format_decimalandformat_floathad duplicated logic, and it'd be easy to modify one function and forget to change the other, causing bugs. This PR forces one source of truth for that logic.What changes are included in this PR?
Created a new helper.
Are these changes tested?
Yes,
passes.
Are there any user-facing changes?
No user facing-changes.