Files
tidb/executor/aggfuncs/func_stddevpop.go
Win-Man 49af6a511f expression: Support stddev_pop function (#19195)
* add stddev_pop function

* fix for make check

* not push down

* add util test

* stddevpop inherit from varpop

* fix typo

* support std and stddev

* update go.mod

* uodate parser master

* fix ditto

* fix fix

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
2020-08-27 19:42:53 +08:00

56 lines
1.5 KiB
Go

// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package aggfuncs
import (
"math"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/chunk"
)
type baseStdDevPopAggFunc struct {
varPop4Float64
}
type stdDevPop4Float64 struct {
baseStdDevPopAggFunc
}
func (e *stdDevPop4Float64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
p := (*partialResult4VarPopFloat64)(pr)
if p.count == 0 {
chk.AppendNull(e.ordinal)
return nil
}
variance := p.variance / float64(p.count)
chk.AppendFloat64(e.ordinal, math.Sqrt(variance))
return nil
}
type stdDevPop4DistinctFloat64 struct {
baseStdDevPopAggFunc
}
func (e *stdDevPop4DistinctFloat64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
p := (*partialResult4VarPopDistinctFloat64)(pr)
if p.count == 0 {
chk.AppendNull(e.ordinal)
return nil
}
variance := p.variance / float64(p.count)
chk.AppendFloat64(e.ordinal, math.Sqrt(variance))
return nil
}