Skip to content

branch-4.1: [fix](be) Return NaN for avg_weighted when sum of weights is zero #64333#64431

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-64333-branch-4.1
Open

branch-4.1: [fix](be) Return NaN for avg_weighted when sum of weights is zero #64333#64431
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-64333-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #64333

…4333)

Problem Summary: When the sum of weights passed to avg_weighted is zero
but the weighted data sum is non-zero, the function computed data_sum /
weight_sum and returned +/-Infinity (e.g. avg_weighted(f1, f2) over rows
(1, 1), (2, -1) returned -Infinity). The expected mathematical result of
a division by zero weight is undefined, so it should return NaN.

This fixes AggregateFunctionAvgWeightedData::get() to return quiet_NaN()
when weight_sum is exactly zero, instead of producing Infinity.
@github-actions github-actions Bot requested a review from yiguolei as a code owner June 11, 2026 12:24
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 0.00% (0/6) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.85% (20388/37861)
Line Coverage 37.43% (193374/516607)
Region Coverage 33.83% (150817/445785)
Branch Coverage 34.83% (66022/189568)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (6/6) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.56% (27238/37030)
Line Coverage 57.20% (294416/514689)
Region Coverage 54.82% (246521/449685)
Branch Coverage 56.27% (106942/190055)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants