diff --git a/expression/bench_test.go b/expression/bench_test.go index c2e29765e0ccc..134be347c67bb 100644 --- a/expression/bench_test.go +++ b/expression/bench_test.go @@ -27,7 +27,6 @@ import ( "time" "github.com/google/uuid" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/auth" "github.com/pingcap/tidb/parser/charset" @@ -41,6 +40,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/math" "github.com/pingcap/tidb/util/mock" + "github.com/stretchr/testify/require" ) type benchHelper struct { @@ -1098,68 +1098,70 @@ func genVecExprBenchCase(ctx sessionctx.Context, funcName string, testCase vecEx // testVectorizedEvalOneVec is used to verify that the vectorized // expression is evaluated correctly during projection -func testVectorizedEvalOneVec(c *C, vecExprCases vecExprBenchCases) { +func testVectorizedEvalOneVec(t *testing.T, vecExprCases vecExprBenchCases) { + t.Parallel() + ctx := mock.NewContext() for funcName, testCases := range vecExprCases { for _, testCase := range testCases { expr, fts, input, output := genVecExprBenchCase(ctx, funcName, testCase) - commentf := func(row int) CommentInterface { - return Commentf("func: %v, case %+v, row: %v, rowData: %v", funcName, testCase, row, input.GetRow(row).GetDatumRow(fts)) + commentf := func(row int) string { + return fmt.Sprintf("func: %v, case %+v, row: %v, rowData: %v", funcName, testCase, row, input.GetRow(row).GetDatumRow(fts)) } output2 := output.CopyConstruct() - c.Assert(evalOneVec(ctx, expr, input, output, 0), IsNil, Commentf("func: %v, case: %+v", funcName, testCase)) + require.NoErrorf(t, evalOneVec(ctx, expr, input, output, 0), "func: %v, case: %+v", funcName, testCase) it := chunk.NewIterator4Chunk(input) - c.Assert(evalOneColumn(ctx, expr, it, output2, 0), IsNil, Commentf("func: %v, case: %+v", funcName, testCase)) + require.NoErrorf(t, evalOneColumn(ctx, expr, it, output2, 0), "func: %v, case: %+v", funcName, testCase) c1, c2 := output.Column(0), output2.Column(0) switch expr.GetType().EvalType() { case types.ETInt: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetInt64(i), Equals, c2.GetInt64(i), commentf(i)) + require.Equal(t, c1.GetInt64(i), c2.GetInt64(i), commentf(i)) } } case types.ETReal: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetFloat64(i), Equals, c2.GetFloat64(i), commentf(i)) + require.Equal(t, c1.GetFloat64(i), c2.GetFloat64(i), commentf(i)) } } case types.ETDecimal: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetDecimal(i), DeepEquals, c2.GetDecimal(i), commentf(i)) + require.Equal(t, c1.GetDecimal(i), c2.GetDecimal(i), commentf(i)) } } case types.ETDatetime, types.ETTimestamp: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetTime(i), DeepEquals, c2.GetTime(i), commentf(i)) + require.Equal(t, c1.GetTime(i), c2.GetTime(i), commentf(i)) } } case types.ETDuration: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetDuration(i, 0), Equals, c2.GetDuration(i, 0), commentf(i)) + require.Equal(t, c1.GetDuration(i, 0), c2.GetDuration(i, 0), commentf(i)) } } case types.ETJson: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetJSON(i), DeepEquals, c2.GetJSON(i), commentf(i)) + require.Equal(t, c1.GetJSON(i), c2.GetJSON(i), commentf(i)) } } case types.ETString: for i := 0; i < input.NumRows(); i++ { - c.Assert(c1.IsNull(i), Equals, c2.IsNull(i), commentf(i)) + require.Equal(t, c1.IsNull(i), c2.IsNull(i), commentf(i)) if !c1.IsNull(i) { - c.Assert(c1.GetString(i), Equals, c2.GetString(i), commentf(i)) + require.Equal(t, c1.GetString(i), c2.GetString(i), commentf(i)) } } } @@ -1299,7 +1301,9 @@ func removeTestOptions(args []string) []string { // testVectorizedBuiltinFunc is used to verify that the vectorized // expression is evaluated correctly -func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { +func testVectorizedBuiltinFunc(t *testing.T, vecExprCases vecExprBenchCases) { + t.Parallel() + testFunc := make(map[string]bool) argList := removeTestOptions(flag.Args()) testAll := len(argList) == 0 @@ -1310,7 +1314,7 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { for _, testCase := range testCases { ctx := mock.NewContext() err := ctx.GetSessionVars().SetSystemVar(variable.BlockEncryptionMode, testCase.aesModes) - c.Assert(err, IsNil) + require.NoError(t, err) if funcName == ast.CurrentUser || funcName == ast.User { ctx.GetSessionVars().User = &auth.UserIdentity{ Username: "tidb", @@ -1346,9 +1350,9 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { continue } // do not forget to implement the vectorized method. - c.Assert(baseFunc.vectorized(), IsTrue, Commentf("func: %v, case: %+v", baseFuncName, testCase)) - commentf := func(row int) CommentInterface { - return Commentf("func: %v, case %+v, row: %v, rowData: %v", baseFuncName, testCase, row, input.GetRow(row).GetDatumRow(fts)) + require.Truef(t, baseFunc.vectorized(), "func: %v, case: %+v", baseFuncName, testCase) + commentf := func(row int) string { + return fmt.Sprintf("func: %v, case %+v, row: %v, rowData: %v", baseFuncName, testCase, row, input.GetRow(row).GetDatumRow(fts)) } it := chunk.NewIterator4Chunk(input) i := 0 @@ -1356,125 +1360,125 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { switch testCase.retEvalType { case types.ETInt: err := baseFunc.vecEvalInt(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() i64s := output.Int64s() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalInt(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(val, Equals, i64s[i], commentf(i)) + require.Equal(t, i64s[i], val, commentf(i)) } i++ } case types.ETReal: err := baseFunc.vecEvalReal(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() f64s := output.Float64s() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalReal(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(val, Equals, f64s[i], commentf(i)) + require.Equal(t, f64s[i], val, commentf(i)) } i++ } case types.ETDecimal: err := baseFunc.vecEvalDecimal(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() d64s := output.Decimals() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalDecimal(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(*val, Equals, d64s[i], commentf(i)) + require.Equal(t, d64s[i], *val, commentf(i)) } i++ } case types.ETDatetime, types.ETTimestamp: err := baseFunc.vecEvalTime(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() t64s := output.Times() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalTime(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(val, Equals, t64s[i], commentf(i)) + require.Equal(t, t64s[i], val, commentf(i)) } i++ } case types.ETDuration: err := baseFunc.vecEvalDuration(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() d64s := output.GoDurations() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalDuration(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(val.Duration, Equals, d64s[i], commentf(i)) + require.Equal(t, d64s[i], val.Duration, commentf(i)) } i++ } case types.ETJson: err := baseFunc.vecEvalJSON(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalJSON(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { cmp := json.CompareBinary(val, output.GetJSON(i)) - c.Assert(cmp, Equals, 0, commentf(i)) + require.Zero(t, cmp, commentf(i)) } i++ } case types.ETString: err := baseFunc.vecEvalString(input, output) - c.Assert(err, IsNil, Commentf("func: %v, case: %+v", baseFuncName, testCase)) + require.NoErrorf(t, err, "func: %v, case: %+v", baseFuncName, testCase) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) vecWarnCnt = ctx.GetSessionVars().StmtCtx.WarningCount() for row := it.Begin(); row != it.End(); row = it.Next() { val, isNull, err := baseFunc.evalString(row) - c.Assert(err, IsNil, commentf(i)) - c.Assert(isNull, Equals, output.IsNull(i), commentf(i)) + require.NoErrorf(t, err, commentf(i)) + require.Equal(t, output.IsNull(i), isNull, commentf(i)) if !isNull { - c.Assert(val, Equals, output.GetString(i), commentf(i)) + require.Equal(t, output.GetString(i), val, commentf(i)) } i++ } default: - c.Fatal(fmt.Sprintf("evalType=%v is not supported", testCase.retEvalType)) + t.Fatal(fmt.Sprintf("evalType=%v is not supported", testCase.retEvalType)) } // check warnings totalWarns := ctx.GetSessionVars().StmtCtx.WarningCount() - c.Assert(2*vecWarnCnt, Equals, totalWarns) + require.Equal(t, totalWarns, 2*vecWarnCnt) warns := ctx.GetSessionVars().StmtCtx.GetWarnings() for i := 0; i < int(vecWarnCnt); i++ { - c.Assert(terror.ErrorEqual(warns[i].Err, warns[i+int(vecWarnCnt)].Err), IsTrue) + require.True(t, terror.ErrorEqual(warns[i].Err, warns[i+int(vecWarnCnt)].Err)) } } } @@ -1482,12 +1486,14 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { // testVectorizedBuiltinFuncForRand is used to verify that the vectorized // expression is evaluated correctly -func testVectorizedBuiltinFuncForRand(c *C, vecExprCases vecExprBenchCases) { +func testVectorizedBuiltinFuncForRand(t *testing.T, vecExprCases vecExprBenchCases) { + t.Parallel() + for funcName, testCases := range vecExprCases { - c.Assert(strings.EqualFold("rand", funcName), Equals, true) + require.True(t, strings.EqualFold("rand", funcName)) for _, testCase := range testCases { - c.Assert(len(testCase.childrenTypes), Equals, 0) + require.Len(t, testCase.childrenTypes, 0) ctx := mock.NewContext() baseFunc, _, input, output := genVecBuiltinFuncBenchCase(ctx, funcName, testCase) @@ -1495,20 +1501,20 @@ func testVectorizedBuiltinFuncForRand(c *C, vecExprCases vecExprBenchCases) { tmp := strings.Split(baseFuncName, ".") baseFuncName = tmp[len(tmp)-1] // do not forget to implement the vectorized method. - c.Assert(baseFunc.vectorized(), IsTrue, Commentf("func: %v", baseFuncName)) + require.Truef(t, baseFunc.vectorized(), "func: %v", baseFuncName) switch testCase.retEvalType { case types.ETReal: err := baseFunc.vecEvalReal(input, output) - c.Assert(err, IsNil) + require.NoError(t, err) // do not forget to call ResizeXXX/ReserveXXX - c.Assert(getColumnLen(output, testCase.retEvalType), Equals, input.NumRows()) + require.Equal(t, input.NumRows(), getColumnLen(output, testCase.retEvalType)) // check result res := output.Float64s() for _, v := range res { - c.Assert((0 <= v) && (v < 1), Equals, true) + require.True(t, (0 <= v) && (v < 1)) } default: - c.Fatal(fmt.Sprintf("evalType=%v is not supported", testCase.retEvalType)) + t.Fatal(fmt.Sprintf("evalType=%v is not supported", testCase.retEvalType)) } } } @@ -1795,27 +1801,6 @@ func generateRandomSel() []int { return sel } -func (s *testVectorizeSuite2) TestVecEvalBool(c *C) { - ctx := mock.NewContext() - eTypes := []types.EvalType{types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} - for numCols := 1; numCols <= 5; numCols++ { - for round := 0; round < 16; round++ { - exprs, input := genVecEvalBool(numCols, nil, eTypes) - selected, nulls, err := VecEvalBool(ctx, exprs, input, nil, nil) - c.Assert(err, IsNil) - it := chunk.NewIterator4Chunk(input) - i := 0 - for row := it.Begin(); row != it.End(); row = it.Next() { - ok, null, err := EvalBool(ctx, exprs, row) - c.Assert(err, IsNil) - c.Assert(null, Equals, nulls[i]) - c.Assert(ok, Equals, selected[i]) - i++ - } - } - } -} - func BenchmarkVecEvalBool(b *testing.B) { ctx := mock.NewContext() selected := make([]bool, 0, 1024) @@ -1869,27 +1854,6 @@ func BenchmarkVecEvalBool(b *testing.B) { } } -func (s *testVectorizeSuite2) TestRowBasedFilterAndVectorizedFilter(c *C) { - ctx := mock.NewContext() - eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} - for numCols := 1; numCols <= 5; numCols++ { - for round := 0; round < 16; round++ { - exprs, input := genVecEvalBool(numCols, nil, eTypes) - it := chunk.NewIterator4Chunk(input) - isNull := make([]bool, it.Len()) - selected, nulls, err := rowBasedFilter(ctx, exprs, it, nil, isNull) - c.Assert(err, IsNil) - selected2, nulls2, err2 := vectorizedFilter(ctx, exprs, it, nil, isNull) - c.Assert(err2, IsNil) - length := it.Len() - for i := 0; i < length; i++ { - c.Assert(nulls2[i], Equals, nulls[i]) - c.Assert(selected2[i], Equals, selected[i]) - } - } - } -} - func BenchmarkRowBasedFilterAndVectorizedFilter(b *testing.B) { ctx := mock.NewContext() selected := make([]bool, 0, 1024) @@ -1966,64 +1930,6 @@ func BenchmarkRowBasedFilterAndVectorizedFilter(b *testing.B) { }) } -func (s *testVectorizeSuite2) TestVectorizedFilterConsiderNull(c *C) { - ctx := mock.NewContext() - dafaultEnableVectorizedExpressionVar := ctx.GetSessionVars().EnableVectorizedExpression - eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} - for numCols := 1; numCols <= 5; numCols++ { - for round := 0; round < 16; round++ { - exprs, input := genVecEvalBool(numCols, nil, eTypes) - it := chunk.NewIterator4Chunk(input) - isNull := make([]bool, it.Len()) - ctx.GetSessionVars().EnableVectorizedExpression = false - selected, nulls, err := VectorizedFilterConsiderNull(ctx, exprs, it, nil, isNull) - c.Assert(err, IsNil) - ctx.GetSessionVars().EnableVectorizedExpression = true - selected2, nulls2, err2 := VectorizedFilterConsiderNull(ctx, exprs, it, nil, isNull) - c.Assert(err2, IsNil) - length := it.Len() - for i := 0; i < length; i++ { - c.Assert(nulls2[i], Equals, nulls[i]) - c.Assert(selected2[i], Equals, selected[i]) - } - - // add test which sel is not nil - randomSel := generateRandomSel() - input.SetSel(randomSel) - it2 := chunk.NewIterator4Chunk(input) - isNull = isNull[:0] - ctx.GetSessionVars().EnableVectorizedExpression = false - selected3, nulls, err := VectorizedFilterConsiderNull(ctx, exprs, it2, nil, isNull) - c.Assert(err, IsNil) - ctx.GetSessionVars().EnableVectorizedExpression = true - selected4, nulls2, err2 := VectorizedFilterConsiderNull(ctx, exprs, it2, nil, isNull) - c.Assert(err2, IsNil) - for i := 0; i < length; i++ { - c.Assert(nulls2[i], Equals, nulls[i]) - c.Assert(selected4[i], Equals, selected3[i]) - } - - unselected := make([]bool, length) - // unselected[i] == false means that the i-th row is selected - for i := 0; i < length; i++ { - unselected[i] = true - } - for _, idx := range randomSel { - unselected[idx] = false - } - for i := range selected2 { - if selected2[i] && unselected[i] { - selected2[i] = false - } - } - for i := 0; i < length; i++ { - c.Assert(selected2[i], Equals, selected4[i]) - } - } - } - ctx.GetSessionVars().EnableVectorizedExpression = dafaultEnableVectorizedExpressionVar -} - func TestBenchDaily(t *testing.T) { benchdaily.Run( BenchmarkCastIntAsIntRow, diff --git a/expression/builtin_arithmetic_vec_test.go b/expression/builtin_arithmetic_vec_test.go index 8fe9926a34989..fa6cf5d73b1ae 100644 --- a/expression/builtin_arithmetic_vec_test.go +++ b/expression/builtin_arithmetic_vec_test.go @@ -18,12 +18,12 @@ import ( "math" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" + "github.com/stretchr/testify/require" ) var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{ @@ -182,11 +182,11 @@ var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{ ast.NE: {}, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinArithmeticFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinArithmeticCases) +func TestVectorizedBuiltinArithmeticFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinArithmeticCases) } -func (s *testEvaluatorSuite) TestVectorizedDecimalErrOverflow(c *C) { +func TestVectorizedDecimalErrOverflow(t *testing.T) { ctx := mock.NewContext() testCases := []struct { args []float64 @@ -212,18 +212,17 @@ func (s *testEvaluatorSuite) TestVectorizedDecimalErrOverflow(c *C) { input := chunk.New(fts, 1, 1) dec1, dec2 := new(types.MyDecimal), new(types.MyDecimal) err := dec1.FromFloat64(tt.args[0]) - c.Assert(err, IsNil) + require.NoError(t, err) err = dec2.FromFloat64(tt.args[1]) - c.Assert(err, IsNil) + require.NoError(t, err) input.AppendMyDecimal(0, dec1) input.AppendMyDecimal(1, dec2) cols := []Expression{&Column{Index: 0, RetType: fts[0]}, &Column{Index: 1, RetType: fts[1]}} baseFunc, err := funcs[tt.funcName].getFunction(ctx, cols) - c.Assert(err, IsNil) + require.NoError(t, err) result := chunk.NewColumn(eType2FieldType(types.ETDecimal), 1) err = baseFunc.vecEvalDecimal(input, result) - c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, tt.errStr) + require.EqualError(t, err, tt.errStr) } } diff --git a/expression/builtin_cast_vec_test.go b/expression/builtin_cast_vec_test.go index 63f80f36dfd1f..fb6f39ab4fc43 100644 --- a/expression/builtin_cast_vec_test.go +++ b/expression/builtin_cast_vec_test.go @@ -149,12 +149,12 @@ func (g *datetimeJSONGener) gen() interface{} { return json.CreateBinary(d.String()) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinCastEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinCastCases) +func TestVectorizedBuiltinCastEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinCastCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinCastFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinCastCases) +func TestVectorizedBuiltinCastFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinCastCases) } func (s *testEvaluatorSuite) TestVectorizedCastRealAsTime(c *C) { diff --git a/expression/builtin_compare_vec_generated_test.go b/expression/builtin_compare_vec_generated_test.go index d0bb5b2075710..247111e3be448 100644 --- a/expression/builtin_compare_vec_generated_test.go +++ b/expression/builtin_compare_vec_generated_test.go @@ -19,7 +19,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -155,12 +154,12 @@ var vecGeneratedBuiltinCompareCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinCompareEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecGeneratedBuiltinCompareCases) +func TestVectorizedGeneratedBuiltinCompareEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecGeneratedBuiltinCompareCases) } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinCompareFunc(c *C) { - testVectorizedBuiltinFunc(c, vecGeneratedBuiltinCompareCases) +func TestVectorizedGeneratedBuiltinCompareFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecGeneratedBuiltinCompareCases) } func BenchmarkVectorizedGeneratedBuiltinCompareEvalOneVec(b *testing.B) { diff --git a/expression/builtin_compare_vec_test.go b/expression/builtin_compare_vec_test.go index ceab622d3b028..6a122b2df489e 100644 --- a/expression/builtin_compare_vec_test.go +++ b/expression/builtin_compare_vec_test.go @@ -17,7 +17,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -150,12 +149,12 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinCompareEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinCompareCases) +func TestVectorizedBuiltinCompareEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinCompareCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinCompareFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinCompareCases) +func TestVectorizedBuiltinCompareFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinCompareCases) } func BenchmarkVectorizedBuiltinCompareEvalOneVec(b *testing.B) { diff --git a/expression/builtin_control_vec_generated_test.go b/expression/builtin_control_vec_generated_test.go index 878ed6458b76e..99317242be271 100644 --- a/expression/builtin_control_vec_generated_test.go +++ b/expression/builtin_control_vec_generated_test.go @@ -20,7 +20,6 @@ import ( "math/rand" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -114,12 +113,12 @@ var vecBuiltinControlCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinControlEvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinControlCases) +func TestVectorizedBuiltinControlEvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinControlCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinControlFuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinControlCases) +func TestVectorizedBuiltinControlFuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinControlCases) } func BenchmarkVectorizedBuiltinControlEvalOneVecGenerated(b *testing.B) { diff --git a/expression/builtin_encryption_vec_test.go b/expression/builtin_encryption_vec_test.go index 4e2e81d6f279d..c7cb9d7f58a11 100644 --- a/expression/builtin_encryption_vec_test.go +++ b/expression/builtin_encryption_vec_test.go @@ -17,7 +17,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -75,8 +74,8 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinEncryptionFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinEncryptionCases) +func TestVectorizedBuiltinEncryptionFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinEncryptionCases) } func BenchmarkVectorizedBuiltinEncryptionFunc(b *testing.B) { diff --git a/expression/builtin_info_vec_test.go b/expression/builtin_info_vec_test.go index 99bcff6d86c38..d4671b6a4a69d 100644 --- a/expression/builtin_info_vec_test.go +++ b/expression/builtin_info_vec_test.go @@ -19,7 +19,6 @@ import ( "math/rand" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" @@ -110,8 +109,8 @@ var vecBuiltinInfoCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinInfoFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinInfoCases) +func TestVectorizedBuiltinInfoFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinInfoCases) } func BenchmarkVectorizedBuiltinInfoFunc(b *testing.B) { diff --git a/expression/builtin_json_vec_test.go b/expression/builtin_json_vec_test.go index 98f3b6bbe5b3c..be67199440f00 100644 --- a/expression/builtin_json_vec_test.go +++ b/expression/builtin_json_vec_test.go @@ -17,7 +17,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -141,8 +140,8 @@ var vecBuiltinJSONCases = map[string][]vecExprBenchCase{ }, } -func (s *testVectorizeSuite2) TestVectorizedBuiltinJSONFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinJSONCases) +func TestVectorizedBuiltinJSONFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinJSONCases) } func BenchmarkVectorizedBuiltinJSONFunc(b *testing.B) { diff --git a/expression/builtin_like_vec_test.go b/expression/builtin_like_vec_test.go index be069c13daf57..6a9f00efc9503 100644 --- a/expression/builtin_like_vec_test.go +++ b/expression/builtin_like_vec_test.go @@ -17,7 +17,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -33,8 +32,8 @@ var vecBuiltinLikeCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinLikeFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinLikeCases) +func TestVectorizedBuiltinLikeFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinLikeCases) } func BenchmarkVectorizedBuiltinLikeFunc(b *testing.B) { diff --git a/expression/builtin_math_vec_test.go b/expression/builtin_math_vec_test.go index 2f63befe69717..a03bc4524f47f 100644 --- a/expression/builtin_math_vec_test.go +++ b/expression/builtin_math_vec_test.go @@ -17,7 +17,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -136,16 +135,16 @@ var vecBuiltinMathCases1 = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinMathEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinMathCases) +func TestVectorizedBuiltinMathEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinMathCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinMathFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinMathCases) +func TestVectorizedBuiltinMathFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinMathCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinMathFuncForRand(c *C) { - testVectorizedBuiltinFuncForRand(c, vecBuiltinMathCases1) +func TestVectorizedBuiltinMathFuncForRand(t *testing.T) { + testVectorizedBuiltinFuncForRand(t, vecBuiltinMathCases1) } func BenchmarkVectorizedBuiltinMathEvalOneVec(b *testing.B) { diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index 1a3d25c9f577c..83e0eb67ebe49 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -110,12 +110,12 @@ var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinMiscellaneousEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinMiscellaneousCases) +func TestVectorizedBuiltinMiscellaneousEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinMiscellaneousCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinMiscellaneousFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinMiscellaneousCases) +func TestVectorizedBuiltinMiscellaneousFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinMiscellaneousCases) } func BenchmarkVectorizedBuiltinMiscellaneousEvalOneVec(b *testing.B) { diff --git a/expression/builtin_op_vec_test.go b/expression/builtin_op_vec_test.go index a9ded212ba867..959d176e22d01 100644 --- a/expression/builtin_op_vec_test.go +++ b/expression/builtin_op_vec_test.go @@ -152,8 +152,8 @@ func makeBinaryLogicOpDataGeners() []dataGenerator { makeGivenValsOrDefaultGener(arg1s, types.ETInt)} } -func (s *testEvaluatorSuite) TestVectorizedBuiltinOpFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinOpCases) +func TestVectorizedBuiltinOpFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinOpCases) } func BenchmarkVectorizedBuiltinOpFunc(b *testing.B) { diff --git a/expression/builtin_other_vec_generated_test.go b/expression/builtin_other_vec_generated_test.go index 7bebf2b86f7d5..2c571519086ce 100644 --- a/expression/builtin_other_vec_generated_test.go +++ b/expression/builtin_other_vec_generated_test.go @@ -22,7 +22,6 @@ import ( "testing" "time" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -283,12 +282,12 @@ var vecBuiltinOtherGeneratedCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherEvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinOtherGeneratedCases) +func TestVectorizedBuiltinOtherEvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinOtherGeneratedCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherFuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinOtherGeneratedCases) +func TestVectorizedBuiltinOtherFuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinOtherGeneratedCases) } func BenchmarkVectorizedBuiltinOtherEvalOneVecGenerated(b *testing.B) { diff --git a/expression/builtin_other_vec_test.go b/expression/builtin_other_vec_test.go index 0caa36eb73f08..c0b7833abcb55 100644 --- a/expression/builtin_other_vec_test.go +++ b/expression/builtin_other_vec_test.go @@ -54,8 +54,8 @@ var vecBuiltinOtherCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltinOtherFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinOtherCases) +func TestVectorizedBuiltinOtherFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinOtherCases) } func BenchmarkVectorizedBuiltinOtherFunc(b *testing.B) { diff --git a/expression/builtin_string_vec_generated_test.go b/expression/builtin_string_vec_generated_test.go index 830a77a5913d7..010f657c378d1 100644 --- a/expression/builtin_string_vec_generated_test.go +++ b/expression/builtin_string_vec_generated_test.go @@ -19,7 +19,6 @@ package expression import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -35,12 +34,12 @@ var vecGeneratedBuiltinStringCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinStringEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecGeneratedBuiltinStringCases) +func TestVectorizedGeneratedBuiltinStringEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecGeneratedBuiltinStringCases) } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinStringFunc(c *C) { - testVectorizedBuiltinFunc(c, vecGeneratedBuiltinStringCases) +func TestVectorizedGeneratedBuiltinStringFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecGeneratedBuiltinStringCases) } func BenchmarkVectorizedGeneratedBuiltinStringEvalOneVec(b *testing.B) { diff --git a/expression/builtin_string_vec_test.go b/expression/builtin_string_vec_test.go index 59b5200522531..fdb7868ccb2fd 100644 --- a/expression/builtin_string_vec_test.go +++ b/expression/builtin_string_vec_test.go @@ -18,7 +18,6 @@ import ( "math/rand" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/mysql" @@ -529,12 +528,12 @@ var vecBuiltinStringCases2 = map[string][]vecExprBenchCase{ }, } -func (s *testVectorizeSuite1) TestVectorizedBuiltinStringEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinStringCases) +func TestVectorizedBuiltinStringEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinStringCases) } -func (s *testVectorizeSuite1) TestVectorizedBuiltinStringFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinStringCases) +func TestVectorizedBuiltinStringFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinStringCases) } func BenchmarkVectorizedBuiltinStringEvalOneVec(b *testing.B) { @@ -545,12 +544,12 @@ func BenchmarkVectorizedBuiltinStringFunc(b *testing.B) { benchmarkVectorizedBuiltinFunc(b, vecBuiltinStringCases) } -func (s *testVectorizeSuite1) TestVectorizedBuiltinStringEvalOneVec2(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinStringCases2) +func TestVectorizedBuiltinStringEvalOneVec2(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinStringCases2) } -func (s *testVectorizeSuite1) TestVectorizedBuiltinStringFunc2(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinStringCases2) +func TestVectorizedBuiltinStringFunc2(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinStringCases2) } func BenchmarkVectorizedBuiltinStringEvalOneVec2(b *testing.B) { diff --git a/expression/builtin_time_vec_generated_test.go b/expression/builtin_time_vec_generated_test.go index d8027e5971763..cd8d2c0571ba8 100644 --- a/expression/builtin_time_vec_generated_test.go +++ b/expression/builtin_time_vec_generated_test.go @@ -20,7 +20,6 @@ import ( "math" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -6724,12 +6723,12 @@ var vecBuiltinTimeGeneratedCases = map[string][]vecExprBenchCase{ }, } -func (s *testVectorizeSuite1) TestVectorizedBuiltinTimeEvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinTimeGeneratedCases) +func TestVectorizedBuiltinTimeEvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinTimeGeneratedCases) } -func (s *testVectorizeSuite1) TestVectorizedBuiltinTimeFuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinTimeGeneratedCases) +func TestVectorizedBuiltinTimeFuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinTimeGeneratedCases) } func BenchmarkVectorizedBuiltinTimeEvalOneVecGenerated(b *testing.B) { diff --git a/expression/builtin_time_vec_test.go b/expression/builtin_time_vec_test.go index becce36259f56..819dd0d7bdc5f 100644 --- a/expression/builtin_time_vec_test.go +++ b/expression/builtin_time_vec_test.go @@ -572,12 +572,12 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{ }, } -func (s *testVectorizeSuite2) TestVectorizedBuiltinTimeEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinTimeCases) +func TestVectorizedBuiltinTimeEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinTimeCases) } -func (s *testVectorizeSuite2) TestVectorizedBuiltinTimeFunc(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinTimeCases) +func TestVectorizedBuiltinTimeFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinTimeCases) } func BenchmarkVectorizedBuiltinTimeEvalOneVec(b *testing.B) { diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index 377110f22dd89..535cfa06c445b 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -818,6 +818,106 @@ func (s *testEvaluatorSuite) TestFloat32ColVec(c *C) { c.Assert(col.VecEvalReal(ctx, chk, result), IsNil) } +func (s *testVectorizeSuite2) TestVecEvalBool(c *C) { + ctx := mock.NewContext() + eTypes := []types.EvalType{types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} + for numCols := 1; numCols <= 5; numCols++ { + for round := 0; round < 16; round++ { + exprs, input := genVecEvalBool(numCols, nil, eTypes) + selected, nulls, err := VecEvalBool(ctx, exprs, input, nil, nil) + c.Assert(err, IsNil) + it := chunk.NewIterator4Chunk(input) + i := 0 + for row := it.Begin(); row != it.End(); row = it.Next() { + ok, null, err := EvalBool(ctx, exprs, row) + c.Assert(err, IsNil) + c.Assert(null, Equals, nulls[i]) + c.Assert(ok, Equals, selected[i]) + i++ + } + } + } +} + +func (s *testVectorizeSuite2) TestRowBasedFilterAndVectorizedFilter(c *C) { + ctx := mock.NewContext() + eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} + for numCols := 1; numCols <= 5; numCols++ { + for round := 0; round < 16; round++ { + exprs, input := genVecEvalBool(numCols, nil, eTypes) + it := chunk.NewIterator4Chunk(input) + isNull := make([]bool, it.Len()) + selected, nulls, err := rowBasedFilter(ctx, exprs, it, nil, isNull) + c.Assert(err, IsNil) + selected2, nulls2, err2 := vectorizedFilter(ctx, exprs, it, nil, isNull) + c.Assert(err2, IsNil) + length := it.Len() + for i := 0; i < length; i++ { + c.Assert(nulls2[i], Equals, nulls[i]) + c.Assert(selected2[i], Equals, selected[i]) + } + } + } +} + +func (s *testVectorizeSuite2) TestVectorizedFilterConsiderNull(c *C) { + ctx := mock.NewContext() + dafaultEnableVectorizedExpressionVar := ctx.GetSessionVars().EnableVectorizedExpression + eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration} + for numCols := 1; numCols <= 5; numCols++ { + for round := 0; round < 16; round++ { + exprs, input := genVecEvalBool(numCols, nil, eTypes) + it := chunk.NewIterator4Chunk(input) + isNull := make([]bool, it.Len()) + ctx.GetSessionVars().EnableVectorizedExpression = false + selected, nulls, err := VectorizedFilterConsiderNull(ctx, exprs, it, nil, isNull) + c.Assert(err, IsNil) + ctx.GetSessionVars().EnableVectorizedExpression = true + selected2, nulls2, err2 := VectorizedFilterConsiderNull(ctx, exprs, it, nil, isNull) + c.Assert(err2, IsNil) + length := it.Len() + for i := 0; i < length; i++ { + c.Assert(nulls2[i], Equals, nulls[i]) + c.Assert(selected2[i], Equals, selected[i]) + } + + // add test which sel is not nil + randomSel := generateRandomSel() + input.SetSel(randomSel) + it2 := chunk.NewIterator4Chunk(input) + isNull = isNull[:0] + ctx.GetSessionVars().EnableVectorizedExpression = false + selected3, nulls, err := VectorizedFilterConsiderNull(ctx, exprs, it2, nil, isNull) + c.Assert(err, IsNil) + ctx.GetSessionVars().EnableVectorizedExpression = true + selected4, nulls2, err2 := VectorizedFilterConsiderNull(ctx, exprs, it2, nil, isNull) + c.Assert(err2, IsNil) + for i := 0; i < length; i++ { + c.Assert(nulls2[i], Equals, nulls[i]) + c.Assert(selected4[i], Equals, selected3[i]) + } + + unselected := make([]bool, length) + // unselected[i] == false means that the i-th row is selected + for i := 0; i < length; i++ { + unselected[i] = true + } + for _, idx := range randomSel { + unselected[idx] = false + } + for i := range selected2 { + if selected2[i] && unselected[i] { + selected2[i] = false + } + } + for i := 0; i < length; i++ { + c.Assert(selected2[i], Equals, selected4[i]) + } + } + } + ctx.GetSessionVars().EnableVectorizedExpression = dafaultEnableVectorizedExpressionVar +} + func BenchmarkFloat32ColRow(b *testing.B) { col, chk, _ := genFloat32Col() ctx := mock.NewContext() diff --git a/expression/evaluator_test.go b/expression/evaluator_test.go index 361f7196ed570..75a8b77685bc1 100644 --- a/expression/evaluator_test.go +++ b/expression/evaluator_test.go @@ -21,7 +21,6 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" @@ -30,10 +29,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" - "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" - "github.com/pingcap/tidb/util/timeutil" - "github.com/tikv/client-go/v2/tikv" ) var _ = SerialSuites(&testEvaluatorSerialSuites{}) @@ -42,24 +38,9 @@ var _ = Suite(&testVectorizeSuite1{}) var _ = Suite(&testVectorizeSuite2{}) func TestT(t *testing.T) { - config.UpdateGlobal(func(conf *config.Config) { - conf.TiKVClient.AsyncCommit.SafeWindow = 0 - conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 - }) - tikv.EnableFailpoints() - - testleak.BeforeTest() - defer testleak.AfterTestT(t)() - CustomVerboseFlag = true *CustomParallelSuiteFlag = true - // Some test depends on the values of timeutil.SystemLocation() - // If we don't SetSystemTZ() here, the value would change unpredictable. - // Affectd by the order whether a testsuite runs before or after integration test. - // Note, SetSystemTZ() is a sync.Once operation. - timeutil.SetSystemTZ("system") - fpname := "github.com/pingcap/tidb/expression/PanicIfPbCodeUnspecified" err := failpoint.Enable(fpname, "return(true)") if err != nil { diff --git a/expression/generator/compare_vec.go b/expression/generator/compare_vec.go index 27315648c78fe..8330f6ed80bc0 100644 --- a/expression/generator/compare_vec.go +++ b/expression/generator/compare_vec.go @@ -296,7 +296,6 @@ func (b *builtin{{ .compare.CompareName }}{{ .type.TypeName }}Sig) vectorized() const builtinCompareVecTestHeader = `import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -315,12 +314,12 @@ var builtinCompareVecTestFuncTail = ` }, var builtinCompareVecTestTail = `} -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinCompareEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecGeneratedBuiltinCompareCases) +func TestVectorizedGeneratedBuiltinCompareEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecGeneratedBuiltinCompareCases) } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinCompareFunc(c *C) { - testVectorizedBuiltinFunc(c, vecGeneratedBuiltinCompareCases) +func TestVectorizedGeneratedBuiltinCompareFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecGeneratedBuiltinCompareCases) } func BenchmarkVectorizedGeneratedBuiltinCompareEvalOneVec(b *testing.B) { diff --git a/expression/generator/control_vec.go b/expression/generator/control_vec.go index 1b4ec708800df..b67923c3c296a 100644 --- a/expression/generator/control_vec.go +++ b/expression/generator/control_vec.go @@ -492,7 +492,6 @@ import ( "math/rand" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -541,12 +540,12 @@ var vecBuiltin{{.Category}}Cases = map[string][]vecExprBenchCase{ {{ end }} } -func (s *testEvaluatorSuite) TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltinControlCases) +func TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltinControlCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltin{{.Category}}FuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltinControlCases) +func TestVectorizedBuiltin{{.Category}}FuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltinControlCases) } func BenchmarkVectorizedBuiltin{{.Category}}EvalOneVecGenerated(b *testing.B) { diff --git a/expression/generator/other_vec.go b/expression/generator/other_vec.go index 9240d12bf7115..58e6f069aeade 100644 --- a/expression/generator/other_vec.go +++ b/expression/generator/other_vec.go @@ -281,7 +281,6 @@ import ( "testing" "time" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -401,12 +400,12 @@ var vecBuiltin{{ .Category }}GeneratedCases = map[string][]vecExprBenchCase { }, } -func (s *testEvaluatorSuite) TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltin{{.Category}}GeneratedCases) +func TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltin{{.Category}}GeneratedCases) } -func (s *testEvaluatorSuite) TestVectorizedBuiltin{{.Category}}FuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltin{{.Category}}GeneratedCases) +func TestVectorizedBuiltin{{.Category}}FuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltin{{.Category}}GeneratedCases) } func BenchmarkVectorizedBuiltin{{.Category}}EvalOneVecGenerated(b *testing.B) { diff --git a/expression/generator/string_vec.go b/expression/generator/string_vec.go index 74eb8a224427d..4dcc5e66319f3 100644 --- a/expression/generator/string_vec.go +++ b/expression/generator/string_vec.go @@ -116,7 +116,6 @@ var builtinStringVecTestTpl = template.Must(template.New("").Parse(` import ( "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/types" ) @@ -129,12 +128,12 @@ var vecGeneratedBuiltinStringCases = map[string][]vecExprBenchCase{ }, } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinStringEvalOneVec(c *C) { - testVectorizedEvalOneVec(c, vecGeneratedBuiltinStringCases) +func TestVectorizedGeneratedBuiltinStringEvalOneVec(t *testing.T) { + testVectorizedEvalOneVec(t, vecGeneratedBuiltinStringCases) } -func (s *testEvaluatorSuite) TestVectorizedGeneratedBuiltinStringFunc(c *C) { - testVectorizedBuiltinFunc(c, vecGeneratedBuiltinStringCases) +func TestVectorizedGeneratedBuiltinStringFunc(t *testing.T) { + testVectorizedBuiltinFunc(t, vecGeneratedBuiltinStringCases) } func BenchmarkVectorizedGeneratedBuiltinStringEvalOneVec(b *testing.B) { diff --git a/expression/generator/time_vec.go b/expression/generator/time_vec.go index 3177216813789..a0b241a9100d0 100644 --- a/expression/generator/time_vec.go +++ b/expression/generator/time_vec.go @@ -660,7 +660,6 @@ import ( "math" "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" @@ -797,12 +796,12 @@ var vecBuiltin{{.Category}}GeneratedCases = map[string][]vecExprBenchCase{ {{ end }} } -func (s *testVectorizeSuite1) TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(c *C) { - testVectorizedEvalOneVec(c, vecBuiltin{{.Category}}GeneratedCases) +func TestVectorizedBuiltin{{.Category}}EvalOneVecGenerated(t *testing.T) { + testVectorizedEvalOneVec(t, vecBuiltin{{.Category}}GeneratedCases) } -func (s *testVectorizeSuite1) TestVectorizedBuiltin{{.Category}}FuncGenerated(c *C) { - testVectorizedBuiltinFunc(c, vecBuiltin{{.Category}}GeneratedCases) +func TestVectorizedBuiltin{{.Category}}FuncGenerated(t *testing.T) { + testVectorizedBuiltinFunc(t, vecBuiltin{{.Category}}GeneratedCases) } func BenchmarkVectorizedBuiltin{{.Category}}EvalOneVecGenerated(b *testing.B) { diff --git a/expression/main_test.go b/expression/main_test.go new file mode 100644 index 0000000000000..2f3bc7b49cb38 --- /dev/null +++ b/expression/main_test.go @@ -0,0 +1,63 @@ +// Copyright 2021 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, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package expression + +import ( + "testing" + "time" + + "github.com/pingcap/tidb/config" + "github.com/pingcap/tidb/testkit/testmain" + "github.com/pingcap/tidb/util/mock" + "github.com/pingcap/tidb/util/testbridge" + "github.com/pingcap/tidb/util/timeutil" + "github.com/stretchr/testify/require" + "github.com/tikv/client-go/v2/tikv" + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + testbridge.WorkaroundGoCheckFlags() + testmain.ShortCircuitForBench(m) + + config.UpdateGlobal(func(conf *config.Config) { + conf.TiKVClient.AsyncCommit.SafeWindow = 0 + conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 + }) + tikv.EnableFailpoints() + + // Some test depends on the values of timeutil.SystemLocation() + // If we don't SetSystemTZ() here, the value would change unpredictable. + // Affected by the order whether a testsuite runs before or after integration test. + // Note, SetSystemTZ() is a sync.Once operation. + timeutil.SetSystemTZ("system") + + opts := []goleak.Option{ + goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"), + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + } + + goleak.VerifyTestMain(m, opts...) +} + +func createContext(t *testing.T) *mock.Context { + ctx := mock.NewContext() + ctx.GetSessionVars().StmtCtx.TimeZone = time.Local + sc := ctx.GetSessionVars().StmtCtx + sc.TruncateAsWarning = true + require.NoError(t, ctx.GetSessionVars().SetSystemVar("max_allowed_packet", "67108864")) + ctx.GetSessionVars().PlanColumnID = 0 + return ctx +}