Skip to content

fix(agg): support decimal256 variance aggregates - #28841

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28838-decimal256-variance-20260914
Sep 14, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28838-decimal256-variance-20260914

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

issue #28838

What this PR does / why we need it:

Variance and standard-deviation aggregates accepted DECIMAL256 inputs during planning but panicked at runtime in the aggregate executor.

The executor factory now routes DECIMAL256 through the existing numeric variance/stddev state machine while preserving the float64 return type and state/wire layout. Exact decimal-origin deviation handling is retained where representable, with a float64 fallback outside that range. The shared DECIMAL256-to-float64 conversion is also corrected at the signed 128-bit boundary.

Test plan:

  • Full pkg/sql/colexec/aggexec unit and race tests.
  • Full pkg/sql/plan/function unit tests.
  • Full pkg/container/types unit and race tests.
  • DECIMAL256 resident, DISTINCT, merge, empty/singleton, serialization, planner, and signed-boundary tests.
  • make static-check-analysis GOLANGCI_LINT_CONCURRENCY=1 (0 issues).
  • git diff --check.

All listed tests passed.

@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 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head bb32328f3745c5cd30a54a9805bc7e9507ae6ac7. The Decimal256 variance path preserves exact-origin deltas through resident/DISTINCT aggregation, merge and serialization; the Welford/Chan updates, scale conversion/overflow fallback and planner FLOAT64 return type are consistent. NULL, empty and singleton groups plus stable/legacy state layouts are covered. No concrete correctness or cleanup blocker found. Exact-head CI run 34811552609 passed; new tests use 1–4 row vectors, with no credible ~45s test or major racing-UT cost increase.

@XuPeng-SH
XuPeng-SH merged commit be30a70 into matrixorigin:main Sep 14, 2026
18 of 20 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-28838-decimal256-variance-20260914 branch September 14, 2026 07:12
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#28838

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

Variance and standard-deviation aggregates accepted DECIMAL256 inputs
during planning but panicked at runtime in the aggregate executor.

The executor factory now routes DECIMAL256 through the existing numeric
variance/stddev state machine while preserving the float64 return type
and state/wire layout. Exact decimal-origin deviation handling is
retained where representable, with a float64 fallback outside that
range. The shared DECIMAL256-to-float64 conversion is also corrected at
the signed 128-bit boundary.

## Test plan:

- Full `pkg/sql/colexec/aggexec` unit and race tests.
- Full `pkg/sql/plan/function` unit tests.
- Full `pkg/container/types` unit and race tests.
- DECIMAL256 resident, DISTINCT, merge, empty/singleton, serialization,
planner, and signed-boundary tests.
- `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=1` (`0 issues`).
- `git diff --check`.

All listed tests passed.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#28838

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

Variance and standard-deviation aggregates accepted DECIMAL256 inputs
during planning but panicked at runtime in the aggregate executor.

The executor factory now routes DECIMAL256 through the existing numeric
variance/stddev state machine while preserving the float64 return type
and state/wire layout. Exact decimal-origin deviation handling is
retained where representable, with a float64 fallback outside that
range. The shared DECIMAL256-to-float64 conversion is also corrected at
the signed 128-bit boundary.

## Test plan:

- Full `pkg/sql/colexec/aggexec` unit and race tests.
- Full `pkg/sql/plan/function` unit tests.
- Full `pkg/container/types` unit and race tests.
- DECIMAL256 resident, DISTINCT, merge, empty/singleton, serialization,
planner, and signed-boundary tests.
- `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=1` (`0 issues`).
- `git diff --check`.

All listed tests passed.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#28838

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

Variance and standard-deviation aggregates accepted DECIMAL256 inputs
during planning but panicked at runtime in the aggregate executor.

The executor factory now routes DECIMAL256 through the existing numeric
variance/stddev state machine while preserving the float64 return type
and state/wire layout. Exact decimal-origin deviation handling is
retained where representable, with a float64 fallback outside that
range. The shared DECIMAL256-to-float64 conversion is also corrected at
the signed 128-bit boundary.

## Test plan:

- Full `pkg/sql/colexec/aggexec` unit and race tests.
- Full `pkg/sql/plan/function` unit tests.
- Full `pkg/container/types` unit and race tests.
- DECIMAL256 resident, DISTINCT, merge, empty/singleton, serialization,
planner, and signed-boundary tests.
- `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=1` (`0 issues`).
- `git diff --check`.

All listed tests passed.

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.

2 participants