-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Zhuomin(Charming) Liu <lzmhhh123@gmail.com> Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
- Loading branch information
1 parent
1bfeff9
commit 205c401
Showing
9 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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 stddevSamp4Float64 struct { | ||
varPop4Float64 | ||
} | ||
|
||
func (e *stddevSamp4Float64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error { | ||
p := (*partialResult4VarPopFloat64)(pr) | ||
if p.count <= 1 { | ||
chk.AppendNull(e.ordinal) | ||
return nil | ||
} | ||
variance := p.variance / float64(p.count-1) | ||
chk.AppendFloat64(e.ordinal, math.Sqrt(variance)) | ||
return nil | ||
} | ||
|
||
type stddevSamp4DistinctFloat64 struct { | ||
varPop4DistinctFloat64 | ||
} | ||
|
||
func (e *stddevSamp4DistinctFloat64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error { | ||
p := (*partialResult4VarPopDistinctFloat64)(pr) | ||
if p.count <= 1 { | ||
chk.AppendNull(e.ordinal) | ||
return nil | ||
} | ||
variance := p.variance / float64(p.count-1) | ||
chk.AppendFloat64(e.ordinal, math.Sqrt(variance)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package aggfuncs_test | ||
|
||
import ( | ||
. "github.com/pingcap/check" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/mysql" | ||
) | ||
|
||
func (s *testSuite) TestMergePartialResult4Stddevsamp(c *C) { | ||
tests := []aggTest{ | ||
buildAggTester(ast.AggFuncStddevSamp, mysql.TypeDouble, 5, 1.5811388300841898, 1, 1.407885953173359), | ||
} | ||
for _, test := range tests { | ||
s.testMergePartialResult(c, test) | ||
} | ||
} | ||
|
||
func (s *testSuite) TestStddevsamp(c *C) { | ||
tests := []aggTest{ | ||
buildAggTester(ast.AggFuncStddevSamp, mysql.TypeDouble, 5, nil, 1.5811388300841898), | ||
} | ||
for _, test := range tests { | ||
s.testAggFunc(c, test) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 ( | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
type varSamp4Float64 struct { | ||
varPop4Float64 | ||
} | ||
|
||
func (e *varSamp4Float64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error { | ||
p := (*partialResult4VarPopFloat64)(pr) | ||
if p.count <= 1 { | ||
chk.AppendNull(e.ordinal) | ||
return nil | ||
} | ||
variance := p.variance / float64(p.count-1) | ||
chk.AppendFloat64(e.ordinal, variance) | ||
return nil | ||
} | ||
|
||
type varSamp4DistinctFloat64 struct { | ||
varPop4DistinctFloat64 | ||
} | ||
|
||
func (e *varSamp4DistinctFloat64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error { | ||
p := (*partialResult4VarPopDistinctFloat64)(pr) | ||
if p.count <= 1 { | ||
chk.AppendNull(e.ordinal) | ||
return nil | ||
} | ||
variance := p.variance / float64(p.count-1) | ||
chk.AppendFloat64(e.ordinal, variance) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package aggfuncs_test | ||
|
||
import ( | ||
. "github.com/pingcap/check" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/mysql" | ||
) | ||
|
||
func (s *testSuite) TestMergePartialResult4Varsamp(c *C) { | ||
tests := []aggTest{ | ||
buildAggTester(ast.AggFuncVarSamp, mysql.TypeDouble, 5, 2.5, 1, 1.9821428571428572), | ||
} | ||
for _, test := range tests { | ||
s.testMergePartialResult(c, test) | ||
} | ||
} | ||
|
||
func (s *testSuite) TestVarsamp(c *C) { | ||
tests := []aggTest{ | ||
buildAggTester(ast.AggFuncVarSamp, mysql.TypeDouble, 5, nil, 2.5), | ||
} | ||
for _, test := range tests { | ||
s.testAggFunc(c, test) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters