Skip to content

fix: derive decimal rounding result metadata - #28625

Merged
mergify[bot] merged 26 commits into
matrixorigin:mainfrom
daviszhen:codex/decimal-rounding-metadata
Sep 14, 2026
Merged

mergify[bot] merged 26 commits into
matrixorigin:mainfrom
daviszhen:codex/decimal-rounding-metadata

Conversation

@daviszhen

@daviszhen daviszhen commented Sep 10, 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:

Fixes #28593
Part of #28595

What this PR does / why we need it:

  • Derives ROUND and TRUNCATE precision and scale from a constant digits argument.
  • Refines CEIL, CEILING, and FLOOR decimal precision/scale for both one-argument and constant two-argument forms.
  • Keeps the existing Decimal64/Decimal128/Decimal256 physical result type so serialized plans remain executable by older CNs during rolling upgrades; BIGINT lowering is deferred until it can be protected by a protocol-version gate.
  • Preserves DECIMAL(19,0) values outside the signed BIGINT domain without wrapping.
  • Adds binder and execution regression coverage around MaxInt64/MinInt64 and the full DECIMAL(19,0) boundary.

Testing

  • CGO_CFLAGS="-I$PWD/thirdparties/install/include" CGO_LDFLAGS="-L$PWD/thirdparties/install/lib" go test ./pkg/sql/plan/function ./pkg/sql/plan -count=1
  • make build

@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 →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed all current reviewer comments in (fix commit ):\n\n- removed Decimal-to-BIGINT physical lowering so plans remain compatible with older CNs during rolling upgrades;\n- kept in Decimal128 and added execution coverage at MaxInt64/MinInt64, adjacent out-of-range values, and both 19-digit extrema;\n- restored constant two-argument // metadata refinement, including carry-aware precision;\n- merged the latest .\n\nLocal verification passed:\n\n- FAIL github.com/matrixorigin/matrixone/pkg/sql/plan/function [build failed]
FAIL github.com/matrixorigin/matrixone/pkg/sql/plan [build failed]
FAIL\n- [Verify Go package graph]
mkdir -p install
mkdir -p install/include install/lib
using verified installed ONNX Runtime 1.26.0 from install/lib/onnxruntime_arm64.dylib
make[1]: Nothing to be done for `all'.
[Stage jieba dict]
rm -rf /Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/dict
cp -r /Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/pkg/monlp/tokenizer/dict /Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/dict
[Build binary]
CGO_CFLAGS="-I/Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/cgo -I/Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/thirdparties/install/include " go build -mod=readonly -ldflags="-extldflags '-L/Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/cgo -lmo -L/Users/pengzhen/Documents/GitHub/matrixone-28593-rounding/thirdparties/install/lib -Wl,-rpath,@executable_path/lib' -X 'github.com/matrixorigin/matrixone/pkg/version.GoVersion=go version go1.26.5 darwin/arm64' -X 'github.com/matrixorigin/matrixone/pkg/version.BranchName=codex/decimal-rounding-metadata' -X 'github.com/matrixorigin/matrixone/pkg/version.CommitID=f337f93a30' -X 'github.com/matrixorigin/matrixone/pkg/version.BuildTime=1789110030' -X 'github.com/matrixorigin/matrixone/pkg/version.Version=codex/decimal-rounding-metadata'" -o mo-service ./cmd/mo-service\n\nAll four review threads have been replied to and resolved. CI for the new head is running.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed all current reviewer comments in f337f93a30 (fix commit c8d4d6d0a1):

  • removed Decimal-to-BIGINT physical lowering so plans remain compatible with older CNs during rolling upgrades;
  • kept DECIMAL(19,0) in Decimal128 and added execution coverage at MaxInt64/MinInt64, adjacent out-of-range values, and both 19-digit extrema;
  • restored constant two-argument CEIL/CEILING/FLOOR metadata refinement, including carry-aware precision;
  • merged the latest main.

Local verification passed:

  • go test ./pkg/sql/plan/function ./pkg/sql/plan -count=1
  • make build

All four review threads have been replied to and resolved. CI for the new head is running.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Resolved the failing coverage checks at head 77537dea5b.

Root cause from the coverage diagnostics: the only failed assertion was pkg/logservice/TestProbeTestPortRejectsOccupiedSockets/udp. The test selected an ephemeral port using UDP and then assumed that the same numeric TCP port was free. TCP and UDP allocate ephemeral ports independently, so CI already had that TCP port occupied. The later aggregate Coverage failure was only a consequence of the missing successful UT coverage profile.

Fix:

  • select and temporarily reserve the ephemeral port with TCP first;
  • bind the UDP fixture on that exact port before releasing TCP;
  • retain the original assertion that a failed UDP probe closes its temporary TCP listener;
  • merge current upstream main through b349fea56f.

Local validation:

  • focused logservice regression, -count=100: passed;
  • go test ./pkg/sql/plan/function ./pkg/sql/plan -count=1: passed;
  • make build: passed;
  • git diff --check: passed.

A fresh CI run has been triggered by the push.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the complete current four-file change at 77537de against main b349fea. Prior DECIMAL(19,0) wrapping, incompatible BIGINT physical lowering and missing two-argument CEIL/FLOOR refinement are fixed. One P2 maximum-precision metadata blocker remains (inline).

The revised binder preserves Decimal64/128/256 OIDs, so the prior old-CN result-wrapper failure is removed. Nonnegative ROUND/TRUNCATE precision reduction distinguishes carry vs truncation and preserves dynamic/NULL fallback; boundary execution tests now include both signed-int64 neighbors and full 19-digit extrema. The ancillary port fixture reserves TCP while choosing UDP, bounds retries to EADDRINUSE and retains the failed-probe cleanup oracle; it is not evidence about rounding semantics.

Evidence: full diff/history and prior inline findings, exact-head binder/overload/evaluator and CTAS/parser consumers inspected. Reused the author's corrected package/build report and scoped repeated port test report; the earlier malformed comment containing failed build output is not treated as pass evidence. I did not run SQL/native tests, CTAS restore, mixed-version deployment or benchmarks; the finding is source-derived. Head/base rechecked before posting; CI not awaited.

Comment thread pkg/sql/plan/base_binder.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed bfed62b against main@77dbf5464466b1d5ae784e7d17d92cd1c1c8d17d. No remaining concrete blocker found; prior requested changes are closed.

The DECIMAL(65,0), digits=-1 CEIL/CEILING/FLOOR counterexample now caps precision at 65 rather than publishing width 66. The new helper also respects Decimal64/128 bounds while retaining their physical OIDs. Added tests cover family maxima, carry below the maximum, and CTAS plus an equivalent schema parse/build round-trip. Prior DECIMAL(19,0) wrapping and old-CN incompatible BIGINT lowering remain removed; two-argument refinement remains present. Nonnegative ROUND carry precision cannot exceed the input width because that branch requires digits<input.Scale; TRUNCATE excludes the carry. Dynamic/NULL and negative ROUND/TRUNCATE fallbacks are unchanged.

Reviewed the full five-file PR diff, prior inline findings/replies and current delta, including the separate port-fixture fix. No new executor, wire, persisted representation or shared lifecycle is introduced by the rounding change; ordinary-fix design exemption applies. The port helper bounds retry to address-in-use, releases its TCP reservation, and preserves the failed-probe cleanup oracle.

Evidence: reused source review and author-reported focused plan/package/build validation; the new CTAS test exercises schema expressibility, not an executed backup/restore deployment. No independent native suite, mixed-version deployment, benchmark or CI wait. Exact live head/base rechecked immediately before submission.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Synced with the latest upstream main (6602ca0).\n\nLocal verification:\n- go test ./pkg/sql/plan ./pkg/sql/plan/function -count=1\n- make build\n\nAll passed. The branch is no longer behind main and GitHub reports it as mergeable. New head: 03d97de.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Resolved the Ubuntu/x86 UT failure at head f0c708ef8d.

Root cause from ut-diagnostics-34755937428-1-all: TestISCPResumeRecoversAcceptedIteration resumed the executor at 12:55:02, but the recovery path's consumer-table DDL did not commit until 12:55:16 under CI load. The test's 10-second Eventually deadline expired at 12:55:12 and test cleanup then stopped the executor. Therefore the subsequent context canceled / update txn snapshot messages were cleanup consequences, not the initiating failure.

Fix:

  • give the recovery completion assertion 30 seconds of headroom for its DDL and replay transaction;
  • retain the test's existing 5-minute overall context deadline and 10 ms polling interval.

Local verification:

  • make build: passed;
  • go test ./pkg/vm/engine/test -run '^TestISCPResumeRecoversAcceptedIteration$' -count=3 -timeout=5m: passed;
  • git diff --check: passed.

A fresh CI run has been triggered by the push.

@CLAassistant

CLAassistant commented Sep 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-review of exact head fd448b08353703331e1fe721fa53f36715cb09b0 against exact base a68a200c0bfb0c18f1b7f49d26b20b8d0d9b017f: APPROVE.

I read the complete review, inline-comment, author-reply, issue, and resolved-thread history; audited the current five-file diff and the delta since my prior reviewed head e98c59b344e2cd7fce8b4d6eef816c9e40dde335; and traced binding through overload selection, serialized result types, Decimal64/128/256 evaluators, result-vector scaling, CTAS/schema derivation, and the maximum-precision boundary.

All prior blockers are closed. DECIMAL(19,0) and the other decimal domains keep their existing physical OID, so values outside signed BIGINT do not wrap and old CN executors still receive the wrapper family they understand. Constant two-argument CEIL/CEILING/FLOOR refinement is restored. Carry-aware widths stay within the Decimal64/128/256 family maxima, including DECIMAL(65,0) with negative digits, and the added schema round trip prevents publishing DECIMAL(66,0). ROUND and TRUNCATE retain the conservative dynamic/NULL/negative-digits behavior while narrowing the unambiguous nonnegative literal case. The unrelated port-fixture correction and the bounded ISCP recovery deadline change are safe and scoped to tests.

Validation on the exact head: required third-party and CGO artifacts built; focused planner, function, and logservice tests passed; the changed ISCP recovery test passed; git diff --check and gofmt checks passed. I also added a temporary exact-head executor test for ROUND/TRUNCATE/CEIL/FLOOR over DECIMAL(10,4) at the carry boundary 999999.9999, using the newly narrowed result types; all four results and result-vector types passed, and the temporary test was removed. All exact-head CI checks are terminal with no failures.

@mergify

mergify Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-14 03:42 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-14 04:41 UTC · at 887576e6b88f9692748bc46463ced0dedff91ef1 · squash

This pull request spent 58 minutes 8 seconds in the queue, including 57 minutes 38 seconds running CI.

Required conditions to merge

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.

[Compatibility]: TRUNCATE retains DECIMAL input scale instead of the requested precision

5 participants