Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: merge serial tests in bindinfo, expression, parser and statistics #30749

Merged
merged 10 commits into from
Dec 16, 2021
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 0 additions & 89 deletions expression/builtin_like_serial_test.go

This file was deleted.

63 changes: 63 additions & 0 deletions expression/builtin_like_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/tidb/testkit/trequire"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -95,3 +96,65 @@ func TestRegexp(t *testing.T) {
}
}
}

func TestCILike(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
ctx := createContext(t)
tests := []struct {
input string
pattern string
generalMatch int
unicodeMatch int
}{
{"a", "", 0, 0},
{"a", "a", 1, 1},
{"a", "á", 1, 1},
{"a", "b", 0, 0},
{"aA", "Aa", 1, 1},
{"áAb", `Aa%`, 1, 1},
{"áAb", `%ab%`, 1, 1},
{"áAb", `%ab`, 1, 1},
{"ÀAb", "aA_", 1, 1},
{"áééá", "a_%a", 1, 1},
{"áééá", "a%_a", 1, 1},
{"áéá", "a_%a", 1, 1},
{"áéá", "a%_a", 1, 1},
{"áá", "a_%a", 0, 0},
{"áá", "a%_a", 0, 0},
{"áééáííí", "a_%a%", 1, 1},

// performs matching on a per-character basis
// https://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html#operator_like
{"ß", "s%", 1, 0},
{"ß", "%s", 1, 0},
{"ß", "ss", 0, 0},
{"ß", "s", 1, 0},
{"ss", "%ß%", 1, 0},
{"ß", "_", 1, 1},
{"ß", "__", 0, 0},
}
for _, tt := range tests {
comment := fmt.Sprintf(`for input = "%s", pattern = "%s"`, tt.input, tt.pattern)
fc := funcs[ast.Like]
inputs := datumsToConstants(types.MakeDatums(tt.input, tt.pattern, 0))
f, err := fc.getFunction(ctx, inputs)
require.NoError(t, err, comment)
f.setCollator(collate.GetCollator("utf8mb4_general_ci"))
r, err := evalBuiltinFunc(f, chunk.Row{})
require.NoError(t, err, comment)
trequire.DatumEqual(t, types.NewDatum(tt.generalMatch), r, comment)
}

for _, tt := range tests {
comment := fmt.Sprintf(`for input = "%s", pattern = "%s"`, tt.input, tt.pattern)
fc := funcs[ast.Like]
inputs := datumsToConstants(types.MakeDatums(tt.input, tt.pattern, 0))
f, err := fc.getFunction(ctx, inputs)
require.NoError(t, err, comment)
f.setCollator(collate.GetCollator("utf8mb4_unicode_ci"))
r, err := evalBuiltinFunc(f, chunk.Row{})
require.NoError(t, err, comment)
trequire.DatumEqual(t, types.NewDatum(tt.unicodeMatch), r, comment)
}
}
101 changes: 0 additions & 101 deletions expression/builtin_other_serial_test.go

This file was deleted.

73 changes: 73 additions & 0 deletions expression/builtin_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/hack"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -242,3 +244,74 @@ func TestSetVarFromColumn(t *testing.T) {
require.Equal(t, true, ok)
require.Equal(t, "a", sessionVar.GetString())
}

func TestInFunc(t *testing.T) {
ctx := createContext(t)
fc := funcs[ast.In]
decimal1 := types.NewDecFromFloatForTest(123.121)
decimal2 := types.NewDecFromFloatForTest(123.122)
decimal3 := types.NewDecFromFloatForTest(123.123)
decimal4 := types.NewDecFromFloatForTest(123.124)
time1 := types.NewTime(types.FromGoTime(time.Date(2017, 1, 1, 1, 1, 1, 1, time.UTC)), mysql.TypeDatetime, 6)
time2 := types.NewTime(types.FromGoTime(time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC)), mysql.TypeDatetime, 6)
time3 := types.NewTime(types.FromGoTime(time.Date(2017, 1, 3, 1, 1, 1, 1, time.UTC)), mysql.TypeDatetime, 6)
time4 := types.NewTime(types.FromGoTime(time.Date(2017, 1, 4, 1, 1, 1, 1, time.UTC)), mysql.TypeDatetime, 6)
duration1 := types.Duration{Duration: 12*time.Hour + 1*time.Minute + 1*time.Second}
duration2 := types.Duration{Duration: 12*time.Hour + 1*time.Minute}
duration3 := types.Duration{Duration: 12*time.Hour + 1*time.Second}
duration4 := types.Duration{Duration: 12 * time.Hour}
json1 := json.CreateBinary("123")
json2 := json.CreateBinary("123.1")
json3 := json.CreateBinary("123.2")
json4 := json.CreateBinary("123.3")
testCases := []struct {
args []interface{}
res interface{}
}{
{[]interface{}{1, 1, 2, 3}, int64(1)},
{[]interface{}{1, 0, 2, 3}, int64(0)},
{[]interface{}{1, nil, 2, 3}, nil},
{[]interface{}{nil, nil, 2, 3}, nil},
{[]interface{}{uint64(0), 0, 2, 3}, int64(1)},
{[]interface{}{uint64(math.MaxUint64), uint64(math.MaxUint64), 2, 3}, int64(1)},
{[]interface{}{-1, uint64(math.MaxUint64), 2, 3}, int64(0)},
{[]interface{}{uint64(math.MaxUint64), -1, 2, 3}, int64(0)},
{[]interface{}{1, 0, 2, 3}, int64(0)},
{[]interface{}{1.1, 1.2, 1.3}, int64(0)},
{[]interface{}{1.1, 1.1, 1.2, 1.3}, int64(1)},
{[]interface{}{decimal1, decimal2, decimal3, decimal4}, int64(0)},
{[]interface{}{decimal1, decimal2, decimal3, decimal1}, int64(1)},
{[]interface{}{"1.1", "1.1", "1.2", "1.3"}, int64(1)},
{[]interface{}{"1.1", hack.Slice("1.1"), "1.2", "1.3"}, int64(1)},
{[]interface{}{hack.Slice("1.1"), "1.1", "1.2", "1.3"}, int64(1)},
{[]interface{}{time1, time2, time3, time1}, int64(1)},
{[]interface{}{time1, time2, time3, time4}, int64(0)},
{[]interface{}{duration1, duration2, duration3, duration4}, int64(0)},
{[]interface{}{duration1, duration2, duration1, duration4}, int64(1)},
{[]interface{}{json1, json2, json3, json4}, int64(0)},
{[]interface{}{json1, json1, json3, json4}, int64(1)},
}
for _, tc := range testCases {
fn, err := fc.getFunction(ctx, datumsToConstants(types.MakeDatums(tc.args...)))
require.NoError(t, err)
d, err := evalBuiltinFunc(fn, chunk.MutRowFromDatums(types.MakeDatums(tc.args...)).ToRow())
require.NoError(t, err)
require.Equalf(t, tc.res, d.GetValue(), "%v", types.MakeDatums(tc.args))
}
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
strD1 := types.NewCollationStringDatum("a", "utf8_general_ci")
strD2 := types.NewCollationStringDatum("Á", "utf8_general_ci")
fn, err := fc.getFunction(ctx, datumsToConstants([]types.Datum{strD1, strD2}))
require.NoError(t, err)
d, isNull, err := fn.evalInt(chunk.Row{})
require.False(t, isNull)
require.NoError(t, err)
require.Equalf(t, int64(1), d, "%v, %v", strD1, strD2)
chk1 := chunk.NewChunkWithCapacity(nil, 1)
chk1.SetNumVirtualRows(1)
chk2 := chunk.NewChunkWithCapacity([]*types.FieldType{types.NewFieldType(mysql.TypeTiny)}, 1)
err = fn.vecEvalInt(chk1, chk2.Column(0))
require.NoError(t, err)
require.Equal(t, int64(1), chk2.Column(0).GetInt64(0))
}
Loading