Skip to content

fix(agg): propagate decimal AVG overflow errors - #27869

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-27855-main
Aug 30, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-27855-main

Conversation

@ck89119

@ck89119 ck89119 commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #27855

What this PR does / why we need it:

Decimal AVG finalization discarded errors returned by decimal division and result-scale conversion. It could therefore publish wrapped low bits after a physical Decimal128 overflow. A result can also fit the physical Decimal128/256 storage while exceeding the declared DECIMAL(width, scale) coefficient range.

This PR:

  • makes decAvg return division and scale-conversion errors instead of a partial value;
  • validates the final coefficient against the declared result precision (-10^width < coefficient < 10^width) before publishing it;
  • propagates errors through the generic and specialized Decimal64/Decimal128 DISTINCT and non-DISTINCT flush paths;
  • preserves existing results for representable AVG inputs;
  • adds focused positive, negative, DISTINCT, Decimal128, and Decimal256 regression coverage;
  • adds a self-contained SQL BVT for physical overflow, declared-precision overflow, and representable/NULL controls.

Validation:

  • pre-fix exact-head tests reproduced successful publication at both Decimal128(38,12) and Decimal256(65,12) declared-precision boundaries;
  • mo-cgo-test ./pkg/sql/colexec/aggexec: PASS, 79.9% package statement coverage (decAvg: 81.5%; precision-bound helpers: 100%);
  • complete mo-service build: PASS;
  • func_avg_decimal_boundary.test with mo-tester normal comparison: 13/13 PASS twice on the same clean instance;
  • database teardown check after each BVT run: clean.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH
XuPeng-SH merged commit 3a52dd0 into matrixorigin:main Aug 30, 2026
2 of 3 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 30, 2026
@ck89119
ck89119 deleted the issue-27855-main branch August 31, 2026 03:25
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27855

## What this PR does / why we need it:

Decimal AVG finalization discarded errors returned by decimal division
and result-scale conversion. It could therefore publish wrapped low bits
after a physical Decimal128 overflow. A result can also fit the physical
Decimal128/256 storage while exceeding the declared `DECIMAL(width,
scale)` coefficient range.

This PR:

- makes `decAvg` return division and scale-conversion errors instead of
a partial value;
- validates the final coefficient against the declared result precision
(`-10^width < coefficient < 10^width`) before publishing it;
- propagates errors through the generic and specialized
Decimal64/Decimal128 DISTINCT and non-DISTINCT flush paths;
- preserves existing results for representable AVG inputs;
- adds focused positive, negative, DISTINCT, Decimal128, and Decimal256
regression coverage;
- adds a self-contained SQL BVT for physical overflow,
declared-precision overflow, and representable/NULL controls.

Validation:

- pre-fix exact-head tests reproduced successful publication at both
Decimal128(38,12) and Decimal256(65,12) declared-precision boundaries;
- `mo-cgo-test ./pkg/sql/colexec/aggexec`: PASS, 79.9% package statement
coverage (`decAvg`: 81.5%; precision-bound helpers: 100%);
- complete `mo-service` build: PASS;
- `func_avg_decimal_boundary.test` with mo-tester normal comparison:
13/13 PASS twice on the same clean instance;
- database teardown check after each BVT run: clean.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27855

## What this PR does / why we need it:

Decimal AVG finalization discarded errors returned by decimal division
and result-scale conversion. It could therefore publish wrapped low bits
after a physical Decimal128 overflow. A result can also fit the physical
Decimal128/256 storage while exceeding the declared `DECIMAL(width,
scale)` coefficient range.

This PR:

- makes `decAvg` return division and scale-conversion errors instead of
a partial value;
- validates the final coefficient against the declared result precision
(`-10^width < coefficient < 10^width`) before publishing it;
- propagates errors through the generic and specialized
Decimal64/Decimal128 DISTINCT and non-DISTINCT flush paths;
- preserves existing results for representable AVG inputs;
- adds focused positive, negative, DISTINCT, Decimal128, and Decimal256
regression coverage;
- adds a self-contained SQL BVT for physical overflow,
declared-precision overflow, and representable/NULL controls.

Validation:

- pre-fix exact-head tests reproduced successful publication at both
Decimal128(38,12) and Decimal256(65,12) declared-precision boundaries;
- `mo-cgo-test ./pkg/sql/colexec/aggexec`: PASS, 79.9% package statement
coverage (`decAvg`: 81.5%; precision-bound helpers: 100%);
- complete `mo-service` build: PASS;
- `func_avg_decimal_boundary.test` with mo-tester normal comparison:
13/13 PASS twice on the same clean instance;
- database teardown check after each BVT run: clean.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27855

## What this PR does / why we need it:

Decimal AVG finalization discarded errors returned by decimal division
and result-scale conversion. It could therefore publish wrapped low bits
after a physical Decimal128 overflow. A result can also fit the physical
Decimal128/256 storage while exceeding the declared `DECIMAL(width,
scale)` coefficient range.

This PR:

- makes `decAvg` return division and scale-conversion errors instead of
a partial value;
- validates the final coefficient against the declared result precision
(`-10^width < coefficient < 10^width`) before publishing it;
- propagates errors through the generic and specialized
Decimal64/Decimal128 DISTINCT and non-DISTINCT flush paths;
- preserves existing results for representable AVG inputs;
- adds focused positive, negative, DISTINCT, Decimal128, and Decimal256
regression coverage;
- adds a self-contained SQL BVT for physical overflow,
declared-precision overflow, and representable/NULL controls.

Validation:

- pre-fix exact-head tests reproduced successful publication at both
Decimal128(38,12) and Decimal256(65,12) declared-precision boundaries;
- `mo-cgo-test ./pkg/sql/colexec/aggexec`: PASS, 79.9% package statement
coverage (`decAvg`: 81.5%; precision-bound helpers: 100%);
- complete `mo-service` build: PASS;
- `func_avg_decimal_boundary.test` with mo-tester normal comparison:
13/13 PASS twice on the same clean instance;
- database teardown check after each BVT run: clean.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants