Skip to content

refactor: Refactor numeric sign and padding in Spark format_string - #24115

Open
JSOD11 wants to merge 3 commits into
apache:mainfrom
JSOD11:jsod/refactor-format-string-08-05-26
Open

refactor: Refactor numeric sign and padding in Spark format_string#24115
JSOD11 wants to merge 3 commits into
apache:mainfrom
JSOD11:jsod/refactor-format-string-08-05-26

Conversation

@JSOD11

@JSOD11 JSOD11 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

format_decimal and format_float had 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,

cargo t -p datafusion-spark format_string --lib

passes.

Are there any user-facing changes?

No user facing-changes.

@JSOD11
JSOD11 force-pushed the jsod/refactor-format-string-08-05-26 branch from 0f5b352 to 1028dfe Compare August 5, 2026 18:33
@github-actions github-actions Bot added the spark label Aug 5, 2026
@JSOD11
JSOD11 marked this pull request as ready for review August 5, 2026 18:39
@JSOD11

JSOD11 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

cc @kosiew let me know your thoughts

@codecov-commenter

codecov-commenter commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.02%. Comparing base (3e3a92d) to head (75e31d0).
⚠️ Report is 3 commits behind head on main.

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

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

@JSOD11,

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(

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Good idea, just added these tests. Let me know if the change looks like what you had in mind.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor numeric sign and padding in Spark format_string

3 participants