fix(plan): preserve decimal scale casts in case and iff#24572
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Addressed the review concerns in follow-up commit Changes:
Validation rerun locally: Prior full checks on this patch set also passed: Note: the temporary |
…3.0-dev - Add T_decimal256 dispatch in caseFn/iffFn runtime switches - Add types.Decimal256 to generalCaseFn/generalIffFn type constraints - Add T_decimal256 to supportedTypeCast for T_decimal128 - Implement decimal128ToDecimal256 cast using Decimal256FromDecimal128 - Add execution-level unit tests for caseFn/iffFn with decimal256 result - Add BVT coverage for CASE/IFF with decimal128 branches that promote to decimal256 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit 318d413)
(cherry picked from commit 534c092)
(cherry picked from commit a696218)
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed from multiple angles: the CASE/IFF decimal metadata fix is sound, the decimal width/scale promotion logic is consistent, targeted Go tests with -race passed, and the actual diff matches the intended scope. Approving.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24565
What this PR does / why we need it:
This PR fixes a CASE/IFF type-binding bug for mixed DECIMAL scales.
Before this change,
CASE WHENandIFFcould treat DECIMAL branches with the same OID but different scale/width as already matched, so no implicit cast was inserted. In the reported case, theTHENbranch stayed atDECIMAL(23,2)while theELSEbranch produced a multiplication result with scale 7, and the final CASE result was formatted with the wrong scale.This change makes CASE/IFF require casts whenever branch types are not exactly equal to the computed common type, including DECIMAL scale/width differences. It also preserves the maximum DECIMAL scale and width from source branch types when deriving the common return type.
Added coverage:
caseCheckandiffChecktest/distributed/cases/expression/case_when.sqlValidation:
mo-testergenerate/update result forcase_when.sqlmo-testerrun forcase_when.sql: 87/87 passedgo test ./pkg/sql/plan/function -count=1go test ./pkg/sql/plan -count=1git diff --checkmakemake static-check