Skip to content

Conversation

@Yuvraj-cyborg
Copy link
Contributor

Closes #19536 - Median() truncates integers

Rationale for this change:

The current implementation of median() returns the same type as the input. For integer inputs with an even count, this causes truncation when averaging the two middle values (e.g., median(1, 2, 3, 4) returns 2 instead of 2.5).

Changes in PR:

  • Modified return_type to return Float64 for integer inputs (matching percentile_cont behavior)
  • Updated state_fields to store intermediate state as Float64 for integer inputs
  • Updated accumulator to use Float64Type accumulator for integer inputs
  • Updated create_groups_accumulator to use Float64Type groups accumulator for integer inputs
  • Updated MedianAccumulator::update_batch to cast integers to Float64
  • Updated MedianGroupsAccumulator::update_batch to cast integers to Float64
  • Updated DistinctMedianAccumulator::update_batch to cast integers to Float64
  • Updated sqllogictest files to expect Float64 return types for integer inputs

Test Coverage:

Yes - Updated existing sqllogictests in aggregate.slt and aggregate_skip_partial.slt to expect Float64 return types.

Are there any user-facing changes?

Yes - Breaking change: median() now returns Float64 instead of the input integer type for integer inputs. Users who relied on integer return types will need to cast explicitly if needed.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Dec 31, 2025
@Yuvraj-cyborg
Copy link
Contributor Author

cc: @petern48 @alamb

@Jefffrey
Copy link
Contributor

I think we should look into reusing/merging code with percentile_cont here if possible

@Yuvraj-cyborg Yuvraj-cyborg changed the title Fix:c Median() truncates integers by returning Float64 for integer inputs Draft: Fix:c Median() truncates integers by returning Float64 for integer inputs Dec 31, 2025
@Yuvraj-cyborg Yuvraj-cyborg marked this pull request as draft December 31, 2025 19:20
@Yuvraj-cyborg Yuvraj-cyborg changed the title Draft: Fix:c Median() truncates integers by returning Float64 for integer inputs Fix:c Median() truncates integers by returning Float64 for integer inputs Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Median() truncates integers

2 participants