Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Sep 4, 2024
1 parent 86819fd commit b4a7b77
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
20 changes: 20 additions & 0 deletions enginetest/queries/information_schema_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,26 @@ from information_schema.routines where routine_schema = 'mydb' and routine_type
},
},
},
{
Name: "information_schema.columns in expression uses info schema collation",
SetUpScript: []string{
"create table TEST (COL int);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select table_schema, table_name, column_name table_comment from information_schema.columns where (table_name, column_name) in (('TEST', 'COL'));",
Expected: []sql.Row{
{"mydb", "TEST", "COL"},
},
},
{
Query: "select table_schema, table_name, column_name table_comment from information_schema.columns where (table_name, column_name) in (('test', 'col'));",
Expected: []sql.Row{
{"mydb", "TEST", "COL"},
},
},
},
},
}

var SkippedInfoSchemaScripts = []ScriptTest{
Expand Down
27 changes: 25 additions & 2 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7143,7 +7143,6 @@ where
},
},
},

{
Name: "unix_timestamp script tests",
SetUpScript: []string{
Expand Down Expand Up @@ -7174,7 +7173,6 @@ where
},
},
},

{
Name: "name_const queries",
SetUpScript: []string{
Expand Down Expand Up @@ -7258,6 +7256,31 @@ where
},
},
},
{
Name: "mismatched collation using hash in tuples",
SetUpScript: []string{
"create table t (t1 text collate utf8mb4_0900_bin, t2 text collate utf8mb4_0900_ai_ci)",
"insert into t values ('ABC', 'DEF')",
},
Assertions: []ScriptTestAssertion{
{
Query: "select * from t where (t1, t2) in (('ABC', 'DEF'));",
Expected: []sql.Row{
{"ABC", "DEF"},
},
},
{
Query: "select * from t where (t1, t2) in (('ABC', 'def'));",
Expected: []sql.Row{
{"ABC", "DEF"},
},
},
{
Query: "select * from t where (t1, t2) in (('abc', 'DEF'));",
Expected: []sql.Row{},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
18 changes: 13 additions & 5 deletions sql/expression/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,19 @@ func hashOfSimple(ctx *sql.Context, i interface{}, t sql.Type) (uint64, error) {

var str string
coll := sql.Collation_Default
if types.IsTextOnly(t) {
if types.IsTuple(t) {
tup := i.([]interface{})
tupType := t.(types.TupleType)
hashes := make([]uint64, len(tup))
for idx, v := range tup {
h, err := hashOfSimple(ctx, v, tupType[idx])
if err != nil {
return 0, err
}
hashes[idx] = h
}
str = fmt.Sprintf("%v", hashes)
} else if types.IsTextOnly(t) {
coll = t.(sql.StringType).Collation()
if s, ok := i.(string); ok {
str = s
Expand All @@ -288,10 +300,6 @@ func hashOfSimple(ctx *sql.Context, i interface{}, t sql.Type) (uint64, error) {
str = converted.(string)
}
} else {
if types.IsTuple(t) {
coll = getTupleCollation(t.(types.TupleType))
}

x, err := convertOrTruncate(ctx, i, t.Promote())
if err != nil {
return 0, err
Expand Down
17 changes: 17 additions & 0 deletions sql/expression/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,23 @@ func TestHashInTuple(t *testing.T) {
nil,
nil,
},
{
"heterogeneous collations with nested",
expression.NewTuple(
expression.NewLiteral("ABC", types.MustCreateString(sqltypes.VarChar, 20, sql.Collation_Default)),
expression.NewLiteral("def", types.MustCreateString(sqltypes.VarChar, 20, sql.Collation_utf8mb4_0900_ai_ci)),
),
expression.NewTuple(
expression.NewTuple(
expression.NewLiteral("ABC", types.MustCreateString(sqltypes.VarChar, 20, sql.Collation_Default)),
expression.NewLiteral("DEF", types.MustCreateString(sqltypes.VarChar, 20, sql.Collation_Default)),
),
),
nil,
true,
nil,
nil,
},
{
"left get field tuple is in right",
expression.NewTuple(
Expand Down

0 comments on commit b4a7b77

Please sign in to comment.