Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19790 +/- ##
============================================
- Coverage 68.55% 68.54% -0.02%
- Complexity 1470 1486 +16
============================================
Files 3522 3523 +1
Lines 229564 229652 +88
Branches 36457 36470 +13
============================================
+ Hits 157383 157419 +36
- Misses 59851 59920 +69
+ Partials 12330 12313 -17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
PR flow
Maps DECIMAL(p,0) to INT for p≤9, LONG for p≤18, BIG_DECIMAL otherwise in logical and physical plan converters.
AI-generated · Green: added · Yellow: modified · Red: removed · Gray: existing
Diff evidence
Problem
The multi-stage engine maps
DECIMAL(p, 0)toINTwhenp <= 10and toLONGwhenp <= 38.INTcannot hold every 10-digit number, andLONGcannot hold every number with 19 to 38 digits.RexExpressionUtils.fromRexLiteralValuethen callsintValue()/longValue(), which wrap the value without an error.Calcite gives the type
DECIMAL(p, 0)to integer literals beyond theBIGINTrange and toCAST(... AS DECIMAL(p, 0)). Results on master, with both planners:WHERE longCol = 999999999999999999997766279631452241919WHERE longCol < 9223372036854775808Invalid rangeSELECT intCol + 999999999999999999997.77E18WHERE intCol = CAST(3000000000 AS DECIMAL(10, 0))-1294967296SUM(CAST(intCol AS DECIMAL(10, 0)))2147483647SELECT 99999999999999999999 + 1(folded during planning)7.77E18Fix
Map
DECIMAL(p, 0)toINTonly whenp <= 9, toLONGonly whenp <= 18, and toBIG_DECIMALotherwise. The change is inRelToPlanNodeConverterand in its copy for the physical optimizer,PRelToPlanNodeConverter.Compatibility
DECIMAL(10, 0)is nowLONG(wasINT).DECIMAL(19..38, 0)is nowBIG_DECIMAL(wasLONG), so the broker returns it as a string, like otherBIG_DECIMALvalues.SUM,MIN,MAXandAVGover these values change the same way. A plainCAST(x AS DECIMAL)isDECIMAL(2000, 1000), so it does not change.DECIMAL(19..38, 0)are nowDOUBLE_ARRAY(wasLONG_ARRAY). This is the same as arrays withp > 38today (see theBIG_DECIMAL_ARRAYTODO).BIG_DECIMALliterals in plans ([Multi-stage] Fix literal handling #13344), so no new type goes over the wire.Not in this PR
SUM,MAXandMODcompute indouble, so values above 2^53 lose precision. This also happens on master for plainLONGcolumns.RequestUtils.getLiteral.Tests
NumericTypes.json: 16 queries compared with H2, in the leaf stage, in intermediate stages and during planning. 14 fail on master with both planners. The other 2 make sure that aBIGINTpromoted toDECIMAL(19, 0)keeps its exact value.RelToPlanNodeConverterTestandPRelToPlanNodeConverterTest.