Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed May 8, 2024
1 parent 055f83a commit 7d077f7
Show file tree
Hide file tree
Showing 39 changed files with 379 additions and 383 deletions.
16 changes: 8 additions & 8 deletions pkg/expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type benchHelper struct {
func (h *benchHelper) init(b *testing.B) {
numRows := 4 * 1024

h.ctx = mockStmtExprCtx(b, contextstatic.WithLocation(time.Local))
h.ctx = mockStmtExprCtx(contextstatic.WithLocation(time.Local))
h.inputTypes = make([]*types.FieldType, 0, 10)
ftb := types.NewFieldTypeBuilder()
ftb.SetType(mysql.TypeLonglong).SetFlag(mysql.BinaryFlag).SetFlen(mysql.MaxIntWidth).SetCharset(charset.CharsetBin).SetCollate(charset.CollationBin)
Expand Down Expand Up @@ -173,8 +173,8 @@ func BenchmarkScalarFunctionClone(b *testing.B) {
col := &Column{RetType: types.NewFieldType(mysql.TypeLonglong)}
con1 := NewOne()
con2 := NewZero()
add := NewFunctionInternal(mockStmtExprCtx(b), ast.Plus, types.NewFieldType(mysql.TypeLonglong), col, con1)
sub := NewFunctionInternal(mockStmtExprCtx(b), ast.Plus, types.NewFieldType(mysql.TypeLonglong), add, con2)
add := NewFunctionInternal(mockStmtExprCtx(), ast.Plus, types.NewFieldType(mysql.TypeLonglong), col, con1)
sub := NewFunctionInternal(mockStmtExprCtx(), ast.Plus, types.NewFieldType(mysql.TypeLonglong), add, con2)
b.ResetTimer()
for i := 0; i < b.N; i++ {
sub.Clone()
Expand Down Expand Up @@ -1374,7 +1374,7 @@ func testVectorizedEvalOneVec(t *testing.T, vecExprCases vecExprBenchCases) {
// benchmarkVectorizedEvalOneVec is used to get the effect of
// using the vectorized expression evaluations during projection
func benchmarkVectorizedEvalOneVec(b *testing.B, vecExprCases vecExprBenchCases) {
ctx := mockStmtExprCtx(b)
ctx := mockStmtExprCtx()
for funcName, testCases := range vecExprCases {
for _, testCase := range testCases {
expr, _, input, output := genVecExprBenchCase(ctx, funcName, testCase)
Expand Down Expand Up @@ -1706,7 +1706,7 @@ func testVectorizedBuiltinFuncForRand(t *testing.T, vecExprCases vecExprBenchCas
for _, testCase := range testCases {
require.Len(t, testCase.childrenTypes, 0)

ctx := mockStmtExprCtx(t)
ctx := mockStmtExprCtx()
baseFunc, _, input, output := genVecBuiltinFuncBenchCase(ctx, funcName, testCase)
baseFuncName := fmt.Sprintf("%v", reflect.TypeOf(baseFunc))
tmp := strings.Split(baseFuncName, ".")
Expand Down Expand Up @@ -1752,7 +1752,7 @@ func benchmarkVectorizedBuiltinFunc(b *testing.B, vecExprCases vecExprBenchCases
if testCase.aesModes == "" {
testCase.aesModes = "aes-128-ecb"
}
ctx = applyExprCtx(b, ctx, contextstatic.WithBlockEncryptionMode(testCase.aesModes))
ctx = applyExprCtx(ctx, contextstatic.WithBlockEncryptionMode(testCase.aesModes))
if funcName == ast.CurrentUser || funcName == ast.User {
vars.User = &auth.UserIdentity{
Username: "tidb",
Expand Down Expand Up @@ -2019,7 +2019,7 @@ func generateRandomSel() []int {
}

func BenchmarkVecEvalBool(b *testing.B) {
ctx := mockStmtExprCtx(b)
ctx := mockStmtExprCtx()
selected := make([]bool, 0, 1024)
nulls := make([]bool, 0, 1024)
eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration}
Expand Down Expand Up @@ -2073,7 +2073,7 @@ func BenchmarkVecEvalBool(b *testing.B) {
}

func BenchmarkRowBasedFilterAndVectorizedFilter(b *testing.B) {
ctx := mockStmtExprCtx(b)
ctx := mockStmtExprCtx()
selected := make([]bool, 0, 1024)
nulls := make([]bool, 0, 1024)
eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration}
Expand Down
14 changes: 7 additions & 7 deletions pkg/expression/builtin_arithmetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestSetFlenDecimal4RealOrDecimal(t *testing.T) {
}

func TestArithmeticPlus(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
// case: 1
args := []any{int64(12), int64(1)}

Expand Down Expand Up @@ -188,7 +188,7 @@ func TestArithmeticPlus(t *testing.T) {
}

func TestArithmeticMinus(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
// case: 1
args := []any{int64(12), int64(1)}

Expand Down Expand Up @@ -266,7 +266,7 @@ func TestArithmeticMinus(t *testing.T) {
}

func TestArithmeticMultiply(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
testCases := []struct {
args []any
expect []any
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestArithmeticMultiply(t *testing.T) {
}

func TestArithmeticDivide(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
testCases := []struct {
args []any
expect any
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestArithmeticDivide(t *testing.T) {
}

func TestArithmeticIntDivide(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
testCases := []struct {
args []any
expect []any
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestArithmeticIntDivide(t *testing.T) {
}

func TestArithmeticMod(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
testCases := []struct {
args []any
expect any
Expand Down Expand Up @@ -657,7 +657,7 @@ func TestArithmeticMod(t *testing.T) {
}

func TestDecimalErrOverflow(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
testCases := []struct {
args []float64
opd string
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/builtin_arithmetic_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestVectorizedBuiltinArithmeticFunc(t *testing.T) {
}

func TestVectorizedDecimalErrOverflow(t *testing.T) {
ctx := mockStmtExprCtx(t)
ctx := mockStmtExprCtx()
testCases := []struct {
args []float64
funcName string
Expand Down
4 changes: 2 additions & 2 deletions pkg/expression/builtin_cast_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func genCastIntAsInt(ctx BuildContext) (*builtinCastIntAsIntSig, *chunk.Chunk, *
}

func BenchmarkCastIntAsIntRow(b *testing.B) {
ctx := mockStmtExprCtx(b)
ctx := mockStmtExprCtx()
evalCtx := ctx.GetEvalCtx()
cast, input, _ := genCastIntAsInt(ctx)
it := chunk.NewIterator4Chunk(input)
Expand All @@ -55,7 +55,7 @@ func BenchmarkCastIntAsIntRow(b *testing.B) {
}

func BenchmarkCastIntAsIntVec(b *testing.B) {
ctx := mockStmtExprCtx(b)
ctx := mockStmtExprCtx()
evalCtx := ctx.GetEvalCtx()
cast, input, result := genCastIntAsInt(ctx)
b.ResetTimer()
Expand Down
22 changes: 11 additions & 11 deletions pkg/expression/builtin_cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestCastFunctions(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

tp := types.NewFieldType(mysql.TypeString)
tp.SetFlen(5)
Expand Down Expand Up @@ -1099,7 +1099,7 @@ func TestCastFuncSig(t *testing.T) {
}

func TestCastJSONAsDecimalSig(t *testing.T) {
ctx := mockStmtIgnoreTruncateExprCtx(t)
ctx := mockStmtIgnoreTruncateExprCtx()
col := &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}
b, err := newBaseBuiltinFunc(ctx, "", []Expression{col}, types.NewFieldType(mysql.TypeNewDecimal))
require.NoError(t, err)
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func TestCastJSONAsDecimalSig(t *testing.T) {

// TestWrapWithCastAsTypesClasses tests WrapWithCastAsInt/Real/String/decimal.
func TestWrapWithCastAsTypesClasses(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

durationColumn0 := &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}
durationColumn0.RetType.SetDecimal(types.DefaultFsp)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ func TestWrapWithCastAsTime(t *testing.T) {
}

func TestWrapWithCastAsDuration(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

cases := []struct {
expr Expression
Expand Down Expand Up @@ -1361,7 +1361,7 @@ func TestWrapWithCastAsDuration(t *testing.T) {
}

func TestWrapWithCastAsString(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

cases := []struct {
expr Expression
Expand Down Expand Up @@ -1419,7 +1419,7 @@ func TestWrapWithCastAsString(t *testing.T) {
}

func TestWrapWithCastAsJSON(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

input := &Column{RetType: types.NewFieldTypeBuilder().SetType(mysql.TypeJSON).BuildP()}
expr := WrapWithCastAsJSON(ctx, input)
Expand All @@ -1430,7 +1430,7 @@ func TestWrapWithCastAsJSON(t *testing.T) {
}

func TestCastIntAsIntVec(t *testing.T) {
ctx := mockStmtExprCtx(t)
ctx := mockStmtExprCtx()
cast, input, result := genCastIntAsInt(ctx)
require.NoError(t, cast.vecEvalInt(ctx.GetEvalCtx(), input, result))
i64s := result.Int64s()
Expand Down Expand Up @@ -1460,7 +1460,7 @@ func TestCastIntAsIntVec(t *testing.T) {
// for issue https://github.com/pingcap/tidb/issues/16825
func TestCastStringAsDecimalSigWithUnsignedFlagInUnion(t *testing.T) {
col := &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}
ctx := mockStmtExprCtx(t)
ctx := mockStmtExprCtx()
b, err := newBaseBuiltinFunc(ctx, "", []Expression{col}, types.NewFieldType(mysql.TypeNewDecimal))
require.NoError(t, err)
// set `inUnion` to `true`
Expand Down Expand Up @@ -1561,7 +1561,7 @@ func TestCastConstAsDecimalFieldType(t *testing.T) {
// test date
{&Constant{RetType: types.NewFieldTypeBuilder().SetType(mysql.TypeDate).SetFlen(types.UnspecifiedLength).SetDecimal(0).BuildP(), Value: types.NewTimeDatum(types.NewTime(types.FromDate(2020, 10, 10, 10, 10, 10, 110), mysql.TypeDate, 0))}, 8, 0},
}
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
for _, tc := range allTestCase {
expr := WrapWithCastAsDecimal(ctx, tc.input)
require.Equal(t, tc.resultFlen, expr.GetType().GetFlen())
Expand All @@ -1570,7 +1570,7 @@ func TestCastConstAsDecimalFieldType(t *testing.T) {
}

func TestCastBinaryStringAsJSONSig(t *testing.T) {
ctx := mockStmtIgnoreTruncateExprCtx(t)
ctx := mockStmtIgnoreTruncateExprCtx()

// BINARY STRING will be converted to a JSON opaque
// and yield "base64:typeXX:<base64 encoded value>" finally
Expand Down Expand Up @@ -1625,7 +1625,7 @@ func TestCastBinaryStringAsJSONSig(t *testing.T) {
}

func TestCastArrayFunc(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
tbl := []struct {
input any
expected any
Expand Down
4 changes: 2 additions & 2 deletions pkg/expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestVectorizedBuiltinCastFunc(t *testing.T) {

func TestVectorizedCastRealAsTime(t *testing.T) {
col := &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
baseFunc, err := newBaseBuiltinFunc(ctx, "", []Expression{col}, types.NewFieldType(mysql.TypeDatetime))
if err != nil {
panic(err)
Expand Down Expand Up @@ -245,7 +245,7 @@ func genCastRealAsTime() (*chunk.Chunk, []*types.Time) {
// for issue https://github.com/pingcap/tidb/issues/16825
func TestVectorizedCastStringAsDecimalWithUnsignedFlagInUnion(t *testing.T) {
col := &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}
ctx := mockStmtExprCtx(t)
ctx := mockStmtExprCtx()
baseFunc, err := newBaseBuiltinFunc(ctx, "", []Expression{col}, types.NewFieldType(mysql.TypeNewDecimal))
if err != nil {
panic(err)
Expand Down
14 changes: 7 additions & 7 deletions pkg/expression/builtin_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestCompareFunctionWithRefine(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

tblInfo := newTestTableBuilder("").add("a", mysql.TypeLong, mysql.NotNullFlag).build()
tests := []struct {
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestCompareFunctionWithRefine(t *testing.T) {
}

func TestCompare(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

intVal, uintVal, realVal, stringVal, decimalVal := 1, uint64(1), 1.1, "123", types.NewDecFromFloatForTest(123.123)
timeVal := types.NewTime(types.FromGoTime(time.Now()), mysql.TypeDatetime, 6)
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestCompare(t *testing.T) {
}

func TestCoalesce(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()

cases := []struct {
args []any
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestCoalesce(t *testing.T) {
}

func TestIntervalFunc(t *testing.T) {
ctx := mockStmtIgnoreTruncateExprCtx(t)
ctx := mockStmtIgnoreTruncateExprCtx()
for _, test := range []struct {
args []types.Datum
ret int64
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestIntervalFunc(t *testing.T) {

// greatest/least function is compatible with MySQL 8.0
func TestGreatestLeastFunc(t *testing.T) {
ctx := mockStmtIgnoreTruncateExprCtx(t)
ctx := mockStmtIgnoreTruncateExprCtx()
decG := &types.MyDecimal{}
decL := &types.MyDecimal{}

Expand Down Expand Up @@ -391,7 +391,7 @@ func TestGreatestLeastFunc(t *testing.T) {
}

func TestRefineArgsWithCastEnum(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
zeroUintConst := primitiveValsToConstants(ctx, []any{uint64(0)})[0]
enumType := types.NewFieldTypeBuilder().SetType(mysql.TypeEnum).SetElems([]string{"1", "2", "3"}).AddFlag(mysql.EnumSetAsIntFlag).Build()
enumCol := &Column{RetType: &enumType}
Expand All @@ -405,7 +405,7 @@ func TestRefineArgsWithCastEnum(t *testing.T) {
}

func TestIssue46475(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
args := []any{nil, dt, nil}

f, err := newFunctionForTest(ctx, ast.Coalesce, primitiveValsToConstants(ctx, args)...)
Expand Down
6 changes: 3 additions & 3 deletions pkg/expression/builtin_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestCaseWhen(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
tbl := []struct {
Arg []any
Ret any
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestCaseWhen(t *testing.T) {
}

func TestIf(t *testing.T) {
ctx := mockStmtIgnoreTruncateExprCtx(t)
ctx := mockStmtIgnoreTruncateExprCtx()
tbl := []struct {
Arg1 any
Arg2 any
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestIf(t *testing.T) {
}

func TestIfNull(t *testing.T) {
ctx := mockStmtTruncateAsWarningExprCtx(t)
ctx := mockStmtTruncateAsWarningExprCtx()
tbl := []struct {
arg1 any
arg2 any
Expand Down

0 comments on commit 7d077f7

Please sign in to comment.