Skip to content

Deduplicate bucket computation in width_bucket_interval_mdn_exact #26307

Closed

Description

@andygrove

Is your feature request related to a problem or challenge?

width_bucket_interval_mdn_exact (spark/src/function/math/width_bucket.rs#L300-L431) contains two near-identical blocks, "only month" (about L330-L366) and "months equals" (about L368-L424). Each repeats:

  • the ascending/descending out-of-range checks (bucket 0 or num_buckets + 1),
  • the bucket-width computation with its zero / non-finite null guard,
  • the floor-plus-one bucket clamp.

They differ only in how x, l and h are projected to f64 (months vs. day/nanosecond offset relative to l). Duplicated numeric edge-case handling like this is where a boundary fix ends up in only one copy.

Describe the solution you'd like

Extract fn bucket_from_f64(x: f64, l: f64, h: f64, num_buckets: i64, ascending: bool) -> Option<i64> (returning None for null). Each branch then only computes its projected (x, l, h) and calls it. Optionally move the per-row body into a helper returning Option<i64> so the continue chains disappear. The existing width_bucket tests cover the behaviour.

Describe alternatives you've considered

None.

Additional context

This is small and self-contained, a good first issue. Line references are pinned to commit 0d79252.

Activity

  1. added
    enhancementNew feature or request
    help wantedExtra attention is needed
    sparkChanges to datafusion-spark crate
    tech debtCode complexity, duplication or structure that makes the codebase harder to change
    on Oct 14, 2026
  2. nightcityblade commented on Oct 14, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

  3. nightcityblade commented on Oct 14, 2026

    @nightcityblade

    untake

  4. med9110 commented on Oct 14, 2026

    @med9110

    Hi @andygrove, I noticed #26307 is available again. I'd like to extract the shared bucket calculation into bucket_from_f64, preserve existing behavior, and run the width_bucket tests. Would that scope be appropriate?

  5. Shahzeb-DataEngineer commented on Oct 19, 2026

    @Shahzeb-DataEngineer
    Contributor

    I would like to take this one. I will extract the shared bucket_from_f64 helper and keep the existing width_bucket tests passing.

  6. added a commit that references this issue on Oct 24, 2026
    92f170c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededsparkChanges to datafusion-spark cratetech debtCode complexity, duplication or structure that makes the codebase harder to change

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions