Skip to content

Commit

Permalink
cherry pick pingcap#23687 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
lzmhhh123 authored and ti-srebot committed Mar 30, 2021
1 parent 11a9254 commit e720516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ func buildApproxPercentile(sctx sessionctx.Context, aggFuncDesc *aggregation.Agg

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

evalType := aggFuncDesc.Args[0].GetType().EvalType()
if aggFuncDesc.Args[0].GetType().Tp == mysql.TypeBit {
evalType = types.ETString // same as other aggregate function
}
switch aggFuncDesc.Mode {
case aggregation.CompleteMode, aggregation.Partial1Mode, aggregation.FinalMode:
switch aggFuncDesc.Args[0].GetType().EvalType() {
switch evalType {
case types.ETInt:
return &percentileOriginal4Int{base}
case types.ETReal:
Expand Down
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8080,3 +8080,12 @@ func (s *testIntegrationSerialSuite) TestIssue19116(c *C) {
tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5"))
tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5"))
}

func (s *testIntegrationSuite) TestApproximatePercentile(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a bit(10))")
tk.MustExec("insert into t values(b'1111')")
tk.MustQuery("select approx_percentile(a, 10) from t").Check(testkit.Rows("<nil>"))
}

0 comments on commit e720516

Please sign in to comment.