-
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
add sum_decimal method for aggfunc #7096
Conversation
add sum_decimal of aggfunc
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
|
||
type partialResult4SumDecimal struct { | ||
sum types.MyDecimal | ||
count int64 |
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.
maybe we could use a bool value isNull
to indicate whether there exists a sum
value in the partial result?
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 use isNull
instead, you can take the MAX
/MIN
for example
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.
ok
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.
but i can not find the file func_max.go in master.
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.
i find it
} | ||
|
||
|
||
type sumPartial4Decimal struct { |
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.
Probably there is no need to implement the sumPartial4Decimal
? Because no matter what mode is the sum
aggregate function stays in, it always has one parameter and the type is decimal.
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.
yep,i find out that the logic of sumPartial4Decimal and sumOriginal4Decimal are the same.
Would you give me some suggestion on renaming sumOriginal4Decimal?
@@ -0,0 +1,127 @@ | |||
// Copyright 2018 PingCAP, Inc. |
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.
We'd better name this file to func_sum.go
to follow the same file naming style with other aggregate functions.
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.
Is it better to separate SUM(decimal) and SUM(float) to single file?
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.
I think it's better to follow the existing flavors. Not only aggregate functions, but also other components, for example, expression and executors, they all put the code with same functionality in the same source file. 😄
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.
ok,follow the existing flavors
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 rename this file to func_sum.go
return nil | ||
} | ||
|
||
type sumOriginal4Decimal struct { |
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.
It would be nice if you add this implementation to the aggfuncs.go
for code navigating, you can take other aggregate functions listed in aggfuncs.go
as examples 😄
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.
ok
go fmt the file
@laidahe please add build functions for |
support int / uint / decimal for sum
support int / uint / decimal for sum
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.
executor/ aggfuncs/ builder.go
buildSum also should be implemented.
executor/aggfuncs/func_sum.go
Outdated
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
// All the following sum function implementations return the decimal result, |
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.
Why put the comment here?
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.
i delete them
executor/aggfuncs/func_sum.go
Outdated
|
||
func (e *sumAggFunc4Decimal) AllocPartialResult() PartialResult { | ||
p := new(partialResult4SumDecimal) | ||
//p.val = *types.NewDecFromInt(0) should the line un-commented? |
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.
This line can be removed.
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.
ok
executor/aggfuncs/func_sum.go
Outdated
|
||
func (e *sumAggFunc4Decimal) ResetPartialResult(pr PartialResult) { | ||
p := (*partialResult4SumDecimal)(pr) | ||
//p.val = *types.NewDecFromInt(0) should the line un-commented? |
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.
ditto
executor/aggfuncs/func_sum.go
Outdated
// All the following sum function implementations return the decimal result, | ||
// which store the partial results in "partialResult4SumDecimal". | ||
|
||
type partialResult4SumInt struct { |
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.
We do not implement partialResult4SumInt/partialResult4SumUint.
We only need partialResult4SumDecimal and partialResult4SumFloat64.
MySQL only returns type double or type decimal.
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.
ok
PTAL |
@laidahe Please merge master and fix CI |
executor/aggfuncs/builder.go
Outdated
@@ -112,8 +137,8 @@ func buildAvg(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc { | |||
case aggregation.DedupMode: | |||
return nil // not implemented yet. | |||
|
|||
// Build avg functions which consume the original data and update their | |||
// partial results. | |||
// Build avg functions which consume the original data and update their |
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.
why make this change?
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.
maybe the editor mistake.i change it back.
executor/aggfuncs/func_sum.go
Outdated
func (e *sum4Float64) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) error { | ||
p := (*partialResult4SumFloat64)(pr) | ||
for _, row := range rowsInGroup { | ||
input, isNull, err := e.args[0].EvalReal(sctx, row) |
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.
EvalReal(sctx, &row)
can gain better performance.
executor/aggfuncs/func_sum.go
Outdated
p := (*partialResult4SumDecimal)(pr) | ||
newSum := new(types.MyDecimal) | ||
for _, row := range rowsInGroup { | ||
input, isNull, err := e.args[0].EvalDecimal(sctx, row) |
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.
ditto
executor/aggfuncs/func_sum.go
Outdated
func (e *sum4DistinctFloat64) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) error { | ||
p := (*partialResult4SumDistinctFloat64)(pr) | ||
for _, row := range rowsInGroup { | ||
input, isNull, err := e.args[0].EvalReal(sctx, row) |
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.
ditto
executor/aggfuncs/func_sum.go
Outdated
p := (*partialResult4SumDistinctDecimal)(pr) | ||
var newSum types.MyDecimal | ||
for _, row := range rowsInGroup { | ||
input, isNull, err := e.args[0].EvalDecimal(sctx, row) |
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.
ditto
@laidahe you can fix ci by |
executor/aggfuncs/aggfuncs.go
Outdated
@@ -55,6 +55,9 @@ var ( | |||
_ AggFunc = (*avgPartial4Float64)(nil) | |||
_ AggFunc = (*avgOriginal4DistinctFloat64)(nil) | |||
|
|||
_ AggFunc = (*sumAggFunc4Float64)(nil) |
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.
_ AggFunc = (*sum4DistinctFloat64)(nil)
_ AggFunc = (*sum4DistinctDecimal)(nil)
_ AggFunc = (*sum4Decimal)(nil)
_ AggFunc = (*sum4Float64)(nil)
@laidahe CI stil fails. please fix CI. you can run |
/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
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
add sum_decimal method for aggfunc
What have you changed? (mandatory)
partially implement the SUM function under the new aggregate function framework, only implemented the following SUM functions:
SUM(DECIMAL)
the following SUM functions are not implemented:
SUM (DISTINCT DECIMAL)
SUM(DISTINCT FLOAT64)
SUM (FLOAT64)
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
Unit test
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No
Does this PR affect tidb-ansible update? (mandatory)
No
Does this PR need to be added to the release notes? (mandatory)
No
Refer to a related PR or issue link (optional)
6952
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)