Skip to content

Commit

Permalink
Merge branch 'master' into tmp_create_like_placement
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao authored Oct 18, 2021
2 parents a7815fb + 9642736 commit efd95d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 32 deletions.
92 changes: 61 additions & 31 deletions executor/aggfuncs/func_max_min_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ package aggfuncs_test

import (
"fmt"
"testing"
"time"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/executor/aggfuncs"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/testkit"
"github.com/stretchr/testify/require"
)

func maxMinUpdateMemDeltaGens(srcChk *chunk.Chunk, dataType *types.FieldType, isMax bool) (memDeltas []int64, err error) {
Expand Down Expand Up @@ -93,7 +94,9 @@ func minUpdateMemDeltaGens(srcChk *chunk.Chunk, dataType *types.FieldType) (memD
return maxMinUpdateMemDeltaGens(srcChk, dataType, false)
}

func (s *testSuite) TestMergePartialResult4MaxMin(c *C) {
func TestMergePartialResult4MaxMin(t *testing.T) {
t.Parallel()

elems := []string{"e", "d", "c", "b", "a"}
enumA, _ := types.ParseEnum(elems, "a", mysql.DefaultCollationName)
enumC, _ := types.ParseEnum(elems, "c", mysql.DefaultCollationName)
Expand Down Expand Up @@ -130,11 +133,17 @@ func (s *testSuite) TestMergePartialResult4MaxMin(c *C) {
buildAggTester(ast.AggFuncMin, mysql.TypeSet, 5, setC, setC, setC),
}
for _, test := range tests {
s.testMergePartialResult(c, test)
test := test
t.Run(test.funcName, func(t *testing.T) {
t.Parallel()
testMergePartialResult(t, test)
})
}
}

func (s *testSuite) TestMaxMin(c *C) {
func TestMaxMin(t *testing.T) {
t.Parallel()

unsignedType := types.NewFieldType(mysql.TypeLonglong)
unsignedType.Flag |= mysql.UnsignedFlag
tests := []aggTest{
Expand All @@ -159,11 +168,17 @@ func (s *testSuite) TestMaxMin(c *C) {
buildAggTester(ast.AggFuncMin, mysql.TypeJSON, 5, nil, json.CreateBinary(int64(0))),
}
for _, test := range tests {
s.testAggFunc(c, test)
test := test
t.Run(test.funcName, func(t *testing.T) {
t.Parallel()
testAggFunc(t, test)
})
}
}

func (s *testSuite) TestMemMaxMin(c *C) {
func TestMemMaxMin(t *testing.T) {
t.Parallel()

tests := []aggMemTest{
buildAggMemTester(ast.AggFuncMax, mysql.TypeLonglong, 5,
aggfuncs.DefPartialResult4MaxMinIntSize, defaultUpdateMemDeltaGens, false),
Expand Down Expand Up @@ -212,7 +227,11 @@ func (s *testSuite) TestMemMaxMin(c *C) {
aggfuncs.DefPartialResult4MaxMinSetSize, minUpdateMemDeltaGens, false),
}
for _, test := range tests {
s.testAggMemFunc(c, test)
test := test
t.Run(test.aggTest.funcName, func(t *testing.T) {
t.Parallel()
testAggMemFunc(t, test)
})
}
}

Expand Down Expand Up @@ -248,8 +267,13 @@ func testMaxSlidingWindow(tk *testkit.TestKit, tc maxSlidingWindowTestCase) {
result.Check(testkit.Rows(tc.expect...))
}

func (s *testSuite) TestMaxSlidingWindow(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestMaxSlidingWindow(t *testing.T) {
t.Parallel()

store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
testCases := []maxSlidingWindowTestCase{
{
rowType: "bigint",
Expand Down Expand Up @@ -312,26 +336,32 @@ func (s *testSuite) TestMaxSlidingWindow(c *C) {
for _, o := range orderBy {
for _, f := range frameType {
for _, tc := range testCases {
tc.frameType = f
tc.orderBy = o
tk.MustExec("drop table if exists t;")
testMaxSlidingWindow(tk, tc)
t.Run(fmt.Sprintf("%s_%v_%d", tc.rowType, o, f), func(t *testing.T) {
tc.frameType = f
tc.orderBy = o
tk.MustExec("drop table if exists t;")
testMaxSlidingWindow(tk, tc)
})
}
}
}
}

func (s *testSuite) TestDequeReset(c *C) {
func TestDequeReset(t *testing.T) {
t.Parallel()

deque := aggfuncs.NewDeque(true, func(i, j interface{}) int {
return types.CompareInt64(i.(int64), j.(int64))
})
deque.PushBack(0, 12)
deque.Reset()
c.Assert(len(deque.Items), Equals, 0)
c.Assert(deque.IsMax, Equals, true)
require.Len(t, deque.Items, 0)
require.True(t, deque.IsMax)
}

func (s *testSuite) TestDequePushPop(c *C) {
func TestDequePushPop(t *testing.T) {
t.Parallel()

deque := aggfuncs.NewDeque(true, func(i, j interface{}) int {
return types.CompareInt64(i.(int64), j.(int64))
})
Expand All @@ -340,28 +370,28 @@ func (s *testSuite) TestDequePushPop(c *C) {
for i := 0; i < times; i++ {
if i != 0 {
front, isEnd := deque.Front()
c.Assert(isEnd, Equals, false)
c.Assert(front.Item, Equals, 0)
c.Assert(front.Idx, Equals, uint64(0))
require.False(t, isEnd)
require.Zero(t, front.Item)
require.Zero(t, front.Idx)
}
deque.PushBack(uint64(i), i)
back, isEnd := deque.Back()
c.Assert(isEnd, Equals, false)
c.Assert(back.Item, Equals, i)
c.Assert(back.Idx, Equals, uint64(i))
require.False(t, isEnd)
require.Equal(t, back.Item, i)
require.Equal(t, back.Idx, uint64(i))
}

// pops element from back of deque
for i := 0; i < times; i++ {
pair, isEnd := deque.Back()
c.Assert(isEnd, Equals, false)
c.Assert(pair.Item, Equals, times-i-1)
c.Assert(pair.Idx, Equals, uint64(times-i-1))
require.False(t, isEnd)
require.Equal(t, pair.Item, times-i-1)
require.Equal(t, pair.Idx, uint64(times-i-1))
front, isEnd := deque.Front()
c.Assert(isEnd, Equals, false)
c.Assert(front.Item, Equals, 0)
c.Assert(front.Idx, Equals, uint64(0))
require.False(t, isEnd)
require.Zero(t, front.Item)
require.Zero(t, front.Idx)
err := deque.PopBack()
c.Assert(err, IsNil)
require.NoError(t, err)
}
}
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
ast.Radians, ast.Degrees, ast.Conv, ast.CRC32,
ast.JSONLength,
ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton,
ast.Coalesce, ast.ASCII, ast.Length, ast.Trim, ast.Position:
ast.Coalesce, ast.ASCII, ast.Length, ast.Trim, ast.Position, ast.Format:
return true
case ast.Substr, ast.Substring, ast.Left, ast.Right, ast.CharLength, ast.SubstringIndex:
switch function.Function.PbCode() {
Expand Down

0 comments on commit efd95d0

Please sign in to comment.