Skip to content

Refactor scalar min/max dispatch into function-based helpers#22062

Open
kosiew wants to merge 3 commits intoapache:mainfrom
kosiew:macro-22061
Open

Refactor scalar min/max dispatch into function-based helpers#22062
kosiew wants to merge 3 commits intoapache:mainfrom
kosiew:macro-22061

Conversation

@kosiew
Copy link
Copy Markdown
Contributor

@kosiew kosiew commented May 7, 2026

Which issue does this PR close?

Rationale for this change

The existing min_max_scalar_impl! macro combined dispatch, validation, recursion, and control flow into a large macro expansion, making the logic difficult to debug, review, and test in isolation.

This change moves scalar min/max dispatch to a function-based implementation while preserving existing behavior, error messages, and dictionary handling semantics.

What changes are included in this PR?

  • Replaced the min_max_scalar_impl! macro with function-based dispatch logic.

  • Added helper functions to separate responsibilities:

    • min_max_option
    • min_max_float_option
    • ensure_decimal_compatibility
    • min_max_generic_scalar
    • min_max_interval_scalar
    • min_max_dictionary_scalar
    • min_max_scalar_same_variant
  • Kept min_max_scalar as the main entry point and delegated behavior through helper functions.

  • Preserved:

    • existing min/max behavior across scalar types
    • dictionary comparison and rewrapping semantics
    • decimal precision/scale validation behavior
    • float NaN handling via total_cmp
    • existing error classifications and messages
    • compacting behavior for generic scalar comparisons
  • Simplified macro usage by retaining only lightweight ordering-selection macros.

Are these changes tested?

Yes.

Added unit tests covering:

  • core scalar min/max parity behavior
  • float NaN handling using total_cmp
  • decimal mismatch error preservation
  • fixed-size binary mismatch error preservation
  • mixed interval comparison error preservation

Existing dictionary comparison tests are also preserved.

Are there any user-facing changes?

No. This PR is intended to be a refactor only and preserves existing externally visible behavior.

LLM-generated code disclosure

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

kosiew added 3 commits May 7, 2026 14:28
- Removed `min_max_scalar_impl!`
- Added function dispatch for:
- `min_max_scalar_same_variant`
- `min_max_dictionary_scalar`
- `ensure_decimal_compatibility`
- scalar helper functions
- Preserved dictionary unwrap/rewrap behavior
- Added parity/regression tests for:
- core scalar min/max
- float NaN total comparison
- decimal mismatch error
- fixed-size-binary mismatch error
…d improve error messages

- Merged min_max_option and min_max_clone_option
- Replaced clone helper call sites
- Shortened dictionary arms using .map(Some)
- Updated decimal compatibility arguments to (precision, scale) tuples
- Simplified assertions in error test messages
@github-actions github-actions Bot added the functions Changes to functions implementation label May 7, 2026
@kosiew kosiew marked this pull request as ready for review May 7, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor scalar min/max dispatch from macro arms to function-based logic

1 participant