Skip to content

Refactor Spark format_string numeric %c conversion dispatch#22166

Draft
kosiew wants to merge 2 commits into
apache:mainfrom
kosiew:refactor-duplication-01-22163
Draft

Refactor Spark format_string numeric %c conversion dispatch#22166
kosiew wants to merge 2 commits into
apache:mainfrom
kosiew:refactor-duplication-01-22163

Conversation

@kosiew
Copy link
Copy Markdown
Contributor

@kosiew kosiew commented May 14, 2026

Which issue does this PR close?

Rationale for this change

The %c conversion path in Spark format_string duplicated nearly identical logic across all signed and unsigned integer scalar variants. This duplication increased maintenance overhead and the risk of future %c fixes being applied inconsistently.

This change centralizes numeric scalar-to-character conversion in a single helper while preserving existing behavior and error propagation semantics.

What changes are included in this PR?

  • Added a local integer_scalar_to_char helper to centralize integer scalar %c conversion handling.
  • Routed all non-null integer %c conversion paths through the new helper.
  • Removed duplicated %c conversion branches from individual integer scalar match arms.
  • Preserved existing signed/unsigned conversion semantics by continuing to use the existing signed_to_char and unsigned_to_char helpers.
  • Left all non-%c formatting behavior unchanged.

Are these changes tested?

No new tests were added in this PR.

This refactor is intended to preserve existing behavior, and existing %c formatting tests continue to validate valid and invalid code point handling.

Suggested validation command:

cargo test -p datafusion-spark format_char

Are there any user-facing changes?

No. This is a maintainability refactor only and is not intended to change observable behavior or error messages.

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.

kosiew added 2 commits May 14, 2026 16:48
…ction

- Implemented integer_scalar_to_char(&ScalarValue) in format_string.rs
- Routed all integer %c cases through the new helper function
- Preserved null handling and support for other integer formats
- Updated function signature from integer_scalar_to_char(value) to integer_scalar_to_char(scalar)
- Added a centralized non-null integer %c dispatch arm
- Removed 8 redundant %c dispatch arms
- Removed 8 scalar @ bindings
@github-actions github-actions Bot added the spark label May 14, 2026
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.

1 participant