-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expression, planner: fix decimal results for aggregate functions #20017
Merged
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
74c55dc
expression, planner: wrap cast as decimal for aggregate function args
dyzsr cdfeebe
only wrap for scalar function argument case, if, ifnull
dyzsr 9b7ebb8
fix
dyzsr fe0f880
Merge branch 'master' into aggdecimalfrac
dyzsr f5497dd
Merge branch 'master' into aggdecimalfrac
dyzsr c8ee654
add Round in AppendFinalResult2Chunk
dyzsr 54a1b7b
Merge branch 'master' into aggdecimalfrac
wjhuang2016 78f230a
remove empty lines
dyzsr d318ef1
remove needCastAsDecimalAggFuncs
dyzsr 2419d28
Merge branch 'master' into aggdecimalfrac
dyzsr 8cd5ab1
fix
dyzsr e03f332
add test case
dyzsr 686eac9
Merge branch 'master' into aggdecimalfrac
dyzsr 97418e1
Merge branch 'master' into aggdecimalfrac
dyzsr 3176e97
Merge branch 'master' into aggdecimalfrac
dyzsr d120e92
precompute frac
dyzsr aac2717
remove empty line
dyzsr 1de167f
Merge branch 'master' into aggdecimalfrac
qw4990 136d19b
Merge branch 'master' into aggdecimalfrac
dyzsr 16d22ba
Merge branch 'master' into aggdecimalfrac
ti-srebot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,24 @@ var noNeedCastAggFuncs = map[string]struct{}{ | |
ast.AggFuncJsonObjectAgg: {}, | ||
} | ||
|
||
// We need to wrap cast as decimal upon these functions, | ||
// since we need to keep the fraction part of their decimal results | ||
var needCastAsDecimalAggFuncs = map[string]struct{}{ | ||
winoros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ast.AggFuncGroupConcat: {}, | ||
} | ||
|
||
// WrapCastAsDecimalForAggArgs wraps the args of some specific aggregate functions | ||
// with a cast as decimal function. See issue #19426 | ||
func (a *baseFuncDesc) WrapCastAsDecimalForAggArgs(ctx sessionctx.Context) { | ||
if _, ok := needCastAsDecimalAggFuncs[a.Name]; ok { | ||
for i := range a.Args { | ||
if tp := a.Args[i].GetType(); tp.Tp == mysql.TypeNewDecimal { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last argument of |
||
a.Args[i] = expression.BuildCastFunction(ctx, a.Args[i], tp) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// WrapCastForAggArgs wraps the args of an aggregate function with a cast function. | ||
func (a *baseFuncDesc) WrapCastForAggArgs(ctx sessionctx.Context) { | ||
if len(a.Args) == 0 { | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the empty line