-
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
Conversation
/run-all-tests |
/run-all-tests |
PTAL @wjhuang2016 |
executor/aggfuncs/func_first_row.go
Outdated
@@ -16,6 +16,9 @@ package aggfuncs | |||
import ( | |||
"unsafe" | |||
|
|||
"github.com/cznic/mathutil" | |||
"github.com/pingcap/parser/mysql" | |||
|
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The last argument of group_cancat
its separator, is it ok?
expression/aggregation/base_func.go
Outdated
func (a *baseFuncDesc) WrapCastAsDecimalForAggArgs(ctx sessionctx.Context) { | ||
if a.Name == ast.AggFuncGroupConcat { | ||
if tp := a.Args[0].GetType(); tp.Tp == mysql.TypeNewDecimal { | ||
a.Args[0] = expression.BuildCastFunction(ctx, a.Args[0], tp) |
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.
What if the second argument needs to be cast?
select group_concat(a, case when a <= 2 or a > 1000 then 0.0 else b end) from t;
/run-all-tests |
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.
LGTM
/run-all-tests |
/run-common-test tidb-test=pr/1100 |
/merge |
/run-all-tests |
@dyzsr merge failed. |
/run-all-tests |
/merge |
/run-all-tests |
@dyzsr merge failed. |
/run-cherry-picker |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #20984 |
) (#20984) * cherry pick #20017 to release-4.0 Signed-off-by: ti-srebot <ti-srebot@pingcap.com> * resolve conflicts Co-authored-by: dy <34701401+dyzsr@users.noreply.github.com> Co-authored-by: dongyan <dybest@icloud.com> Co-authored-by: Yuanjia Zhang <zhangyuanjia@pingcap.com> Co-authored-by: Yiding Cui <winoros@gmail.com>
What problem does this PR solve?
Issue Number: close #19426, fix PR #19592
Problem Summary:
Execute
Obtained
Expect
What is changed and how it works?
cast as decimal
for arguments ofgroup_concat
to preserve fraction part digits of the results.AppendFinalResult2Chunk
to the argument's precision.Related changes
Check List
Tests
Side effects
Release note