Skip to content
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

executor: support new aggregate funtion APPROX_PERCENTILE #19799

Merged
merged 45 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5288d02
squash
leiysky Sep 14, 2020
60a9065
Merge remote-tracking branch 'origin/master' into feature/percentile-…
leiysky Sep 14, 2020
79bbb42
use selection algorithm
leiysky Sep 15, 2020
1472a3f
fix
leiysky Sep 15, 2020
9753823
fix
leiysky Sep 15, 2020
7b6f2f3
fix test
leiysky Sep 15, 2020
54e7c19
fix percentile formula
leiysky Sep 15, 2020
9060c15
check percentage
leiysky Sep 15, 2020
b6188a4
add comment
leiysky Sep 15, 2020
1e6fcd5
fix test
leiysky Sep 15, 2020
f6f6f4c
Merge branch 'master' into feature/percentile-function
leiysky Sep 15, 2020
2bfb042
add license
leiysky Sep 16, 2020
2a123f5
fix dependency
leiysky Sep 16, 2020
d058280
fix test
leiysky Sep 16, 2020
913d08f
support time
leiysky Sep 16, 2020
a107317
Merge remote-tracking branch 'origin/master' into feature/percentile-…
leiysky Sep 16, 2020
533110d
fix potential overflow
leiysky Sep 16, 2020
5938b20
support duration type
leiysky Sep 16, 2020
4f1015c
fix conflict
leiysky Sep 17, 2020
76e51e7
Merge branch 'master' into feature/percentile-function
leiysky Sep 17, 2020
36f23f3
handle default
leiysky Sep 17, 2020
22cd32e
Merge branch 'feature/percentile-function' of https://github.com/leiy…
leiysky Sep 17, 2020
9fcd3bb
check percentage value when building descriptor
leiysky Sep 17, 2020
77a86c6
fix go mod
leiysky Sep 17, 2020
599d4e5
fix go mod sum
leiysky Sep 17, 2020
5080e71
use unified interface
leiysky Sep 17, 2020
7d84d2d
add err handle
leiysky Sep 17, 2020
06e2a2a
fix
leiysky Sep 17, 2020
eb5c41a
fix benchmark
leiysky Sep 20, 2020
e10c67a
Merge branch 'master' into feature/percentile-function
leiysky Sep 20, 2020
8627dc5
Merge branch 'master' into feature/percentile-function
leiysky Sep 21, 2020
90cd4ce
fix
leiysky Sep 21, 2020
2cd66a1
enhance error handling
leiysky Sep 21, 2020
9eb24e1
Merge branch 'master' into feature/percentile-function
leiysky Sep 22, 2020
20226d1
fix test
leiysky Sep 22, 2020
80fb453
fix evaluate
leiysky Sep 22, 2020
0de099b
Merge branch 'feature/percentile-function' of https://github.com/leiy…
leiysky Sep 22, 2020
86ba66e
update test case
leiysky Sep 22, 2020
27cb46b
update
leiysky Sep 22, 2020
467d6cf
enhance benchmark
leiysky Sep 23, 2020
6bade13
Merge branch 'master' into feature/percentile-function
leiysky Sep 23, 2020
e2c7a75
log error
leiysky Sep 24, 2020
3066f36
Merge branch 'feature/percentile-function' of https://github.com/leiy…
leiysky Sep 24, 2020
023a5ad
Merge branch 'master' into feature/percentile-function
leiysky Sep 24, 2020
7c6ad90
Merge branch 'master' into feature/percentile-function
ti-srebot Sep 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions executor/aggfuncs/aggfunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ func (s *testSuite) testAggFunc(c *C, p aggTest) {
if p.funcName == ast.AggFuncGroupConcat {
args = append(args, &expression.Constant{Value: types.NewStringDatum(" "), RetType: types.NewFieldType(mysql.TypeString)})
}
if p.funcName == ast.AggFuncApproxPercentile {
args = append(args, &expression.Constant{Value: types.NewIntDatum(50), RetType: types.NewFieldType(mysql.TypeLong)})
}
desc, err := aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, false)
c.Assert(err, IsNil)
if p.orderBy {
Expand Down
5 changes: 5 additions & 0 deletions executor/aggfuncs/aggfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ var (
_ AggFunc = (*approxCountDistinctPartial2)(nil)
_ AggFunc = (*approxCountDistinctFinal)(nil)

// All the AggFunc implementations for "APPROX_PERCENTILE" are listed here.
leiysky marked this conversation as resolved.
Show resolved Hide resolved
_ AggFunc = (*percentileOriginal4Int)(nil)
_ AggFunc = (*percentileOriginal4Real)(nil)
_ AggFunc = (*percentileOriginal4Decimal)(nil)

// All the AggFunc implementations for "FIRSTROW" are listed here.
_ AggFunc = (*firstRow4Decimal)(nil)
_ AggFunc = (*firstRow4Int)(nil)
Expand Down
42 changes: 40 additions & 2 deletions executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ func Build(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDesc, ordinal
return buildBitAnd(aggFuncDesc, ordinal)
case ast.AggFuncVarPop:
return buildVarPop(aggFuncDesc, ordinal)
case ast.AggFuncStddevPop:
return buildStdDevPop(aggFuncDesc, ordinal)
case ast.AggFuncJsonObjectAgg:
return buildJSONObjectAgg(aggFuncDesc, ordinal)
case ast.AggFuncApproxCountDistinct:
return buildApproxCountDistinct(aggFuncDesc, ordinal)
case ast.AggFuncStddevPop:
return buildStdDevPop(aggFuncDesc, ordinal)
case ast.AggFuncApproxPercentile:
return buildApproxPercentile(ctx, aggFuncDesc, ordinal)
case ast.AggFuncVarSamp:
return buildVarSamp(aggFuncDesc, ordinal)
case ast.AggFuncStddevSamp:
Expand Down Expand Up @@ -135,6 +137,42 @@ func buildApproxCountDistinct(aggFuncDesc *aggregation.AggFuncDesc, ordinal int)
return nil
}

func buildApproxPercentile(sctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
if aggFuncDesc.Mode == aggregation.DedupMode {
return nil
}

// Checked while building descriptor
percent, _, err := aggFuncDesc.Args[1].EvalInt(sctx, chunk.Row{})
if err != nil {
// Should not reach here
panic(fmt.Sprintf("Error happened when buildApproxPercentile: %v", err))
leiysky marked this conversation as resolved.
Show resolved Hide resolved
}

base := basePercentile{percent: int(percent), baseAggFunc: baseAggFunc{args: aggFuncDesc.Args, ordinal: ordinal}}

switch aggFuncDesc.Mode {
case aggregation.CompleteMode, aggregation.Partial1Mode, aggregation.FinalMode:
switch aggFuncDesc.Args[0].GetType().EvalType() {
case types.ETInt:
return &percentileOriginal4Int{base}
case types.ETReal:
return &percentileOriginal4Real{base}
case types.ETDecimal:
return &percentileOriginal4Decimal{base}
case types.ETDatetime, types.ETTimestamp:
return &percentileOriginal4Time{base}
leiysky marked this conversation as resolved.
Show resolved Hide resolved
case types.ETDuration:
return &percentileOriginal4Duration{base}
default:
// Return NULL in any case
return &base
}
}

return nil
}

// buildCount builds the AggFunc implementation for function "COUNT".
func buildCount(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
// If mode is DedupMode, we return nil for not implemented.
Expand Down
Loading