Skip to content

Commit 7843ab3

Browse files
authored
Refactor Spark format_string integer conversion dispatch (#22388)
## Which issue does this PR close? * Closes #22163 ## Rationale for this change `ConversionSpecifier::format` contained substantial duplication across integer `ScalarValue` variants for `%d`, `%x`, `%o`, `%s`, and `%c` handling. Each integer width repeated nearly identical conversion logic, making the code harder to maintain and increasing the risk of inconsistent behavior across integer types. This change consolidates integer formatting behavior into shared internal helpers while preserving existing Spark-compatible semantics. ## What changes are included in this PR? * Introduced a local `IntegerValue` enum to normalize signed and unsigned integer handling while preserving width-specific unsigned bit behavior for `%x` and `%o`. * Replaced repeated per-variant integer dispatch branches in `ConversionSpecifier::format` with a shared `format_integer` helper. * Added shared helper methods for: * decimal formatting * unsigned bit formatting * `%c` conversion * decimal string conversion * Added small `macro_rules!` helpers to generate `From<T> for IntegerValue` implementations for signed and unsigned integer families, reducing repetitive conversion boilerplate while preserving width-specific unsigned formatting semantics. * Added `invalid_integer_conversion` helper to centralize integer conversion error generation. * Added table-driven regression coverage for integer formatting behavior across: * signed integer widths * unsigned integer widths * `%d`, `%x`, `%o`, `%s`, and `%c` * null handling behavior ## Are these changes tested? Yes. Added `test_integer_formatting_across_widths` covering: * Signed integer formatting across `Int8`, `Int16`, `Int32`, and `Int64` * Unsigned integer formatting across `UInt8`, `UInt16`, `UInt32`, and `UInt64` * `%d`, `%x`, `%o`, `%s`, and `%c` formatting behavior * Null integer formatting behavior ## Are there any user-facing changes? No intended user-facing behavior changes. This PR is a structural refactor intended to preserve existing Spark-compatible integer formatting semantics. ## LLM-generated code disclosure This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.
1 parent 08bd332 commit 7843ab3

1 file changed

Lines changed: 195 additions & 198 deletions

File tree

0 commit comments

Comments
 (0)