fix: prevent panic in valueDec128Compare when comparing decimal with integer types#24088
Merged
mergify[bot] merged 2 commits intomatrixorigin:3.0-devfrom Apr 9, 2026
Conversation
…integer types (matrixorigin#24081) The comparison function dispatcher (equalFn, greatThanFn, etc.) dispatches based on parameters[0]'s type. When a decimal128 parameter is paired with an int64 parameter (e.g., ROW_NUMBER() result compared with a decimal literal), valueDec128Compare tries to read 8-byte int64 data as 16-byte Decimal128, causing: panic unsafe slice cast: from length 8 is not enough for length 16 Fix: - Add T_decimal64 and T_decimal128 to isNumericType() so the type-mismatch fallback path (shouldUseTypeMismatchPath) catches decimal-vs-integer mismatches - Add decimal conversion cases in getAsFloat64Slice() using Decimal64ToFloat64 and Decimal128ToFloat64 Approved by: @jiangxinmeng1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
XuPeng-SH
approved these changes
Apr 8, 2026
Contributor
XuPeng-SH
left a comment
There was a problem hiding this comment.
Code Review Summary
LGTM ✅
Changes Reviewed
isNumericType()- Correctly extended to includeT_decimal64andT_decimal128getAsFloat64Slice()- Properly added decimal→float64 conversion usingDecimal64ToFloat64()andDecimal128ToFloat64()with correct Scale handling- Test coverage - Comprehensive tests for all new functionality
Root Cause
When comparing decimal128 with int64 (e.g., ROW_NUMBER() = 2), the comparison function tried to read 8-byte int64 data as 16-byte Decimal128, causing panic:
panic unsafe slice cast: from length 8 is not enough for length 16
Fix Mechanism
The fix correctly leverages the existing type-mismatch fallback path by:
- Recognizing decimal types as numeric in
isNumericType() - Converting decimal values to float64 for comparison when type mismatch is detected
Potential Note
Decimal→float64 conversion has precision loss (38 digits → 15-16 digits), but this is acceptable for the fallback path. For ROW_NUMBER() comparisons (integer values), precision is preserved.
All tests pass ✅
25a112a to
68a2b48
Compare
49e4dc5 to
ad0bf58
Compare
heni02
approved these changes
Apr 8, 2026
aunjgr
approved these changes
Apr 8, 2026
ad0bf58 to
9e20b7a
Compare
Contributor
Merge Queue Status
This pull request spent 13 seconds in the queue, including 1 second running CI. Required conditions to merge
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24081
What this PR does / why we need it:
When executing a window function query like:
The filter
x.rn = 2panics with:Root cause: The comparison dispatcher (
equalFn) selectsvalueDec128Comparebased on one parameter's type (decimal128). When the other parameter is int64 (from ROW_NUMBER()), it tries to read 8-byte int64 data as 16-byte Decimal128, causing a panic.Fix: Extend the existing type-mismatch fallback mechanism in
func_compare_fix.go:T_decimal64andT_decimal128toisNumericType()soshouldUseTypeMismatchPath()catches decimal-vs-integer mismatchesgetAsFloat64Slice()usingDecimal64ToFloat64/Decimal128ToFloat64Test coverage
Added tests:
TestEqualFnDecimalIntMismatch— reproduces the exact panic scenario (decimal128 == int64, int64 == decimal128, decimal64 == decimal128)TestIsNumericTypeandTestShouldUseTypeMismatchPathfor decimal typesTestGetAsFloat64Slice