From bb55e9c31b217f0f6727d8ba142c3f79a04ab744 Mon Sep 17 00:00:00 2001 From: SeaRise Date: Mon, 18 Oct 2021 10:46:41 +0800 Subject: [PATCH 1/2] expression: format pushdown (#28269) --- expression/expression.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/expression.go b/expression/expression.go index 4c8c2f79b82c0..5c4cdd88cc759 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -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() { From 964273677d16675432cc9a8172937b8989ed6297 Mon Sep 17 00:00:00 2001 From: Yoichiro Shimizu Date: Mon, 18 Oct 2021 12:48:41 +0900 Subject: [PATCH 2/2] executor/aggfuncs: refactor: migrate test-infra to testify for func_max_min_test.go (#28695) --- executor/aggfuncs/func_max_min_test.go | 92 +++++++++++++++++--------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/executor/aggfuncs/func_max_min_test.go b/executor/aggfuncs/func_max_min_test.go index 10fc14095f292..b33c72de903cd 100644 --- a/executor/aggfuncs/func_max_min_test.go +++ b/executor/aggfuncs/func_max_min_test.go @@ -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) { @@ -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) @@ -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{ @@ -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), @@ -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) + }) } } @@ -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", @@ -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)) }) @@ -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) } }