Skip to content

Commit

Permalink
test: update test expectations
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Feb 6, 2024
1 parent dfe8e6e commit 3c92aed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
3 changes: 3 additions & 0 deletions go/test/endtoend/vtgate/queries/subquery/subquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ func TestSubqueryInAggregation(t *testing.T) {
mcmp.Exec("insert into t1(id1, id2) values(0,0),(1,1)")
mcmp.Exec("insert into t2(id3, id4) values(1,2),(5,7)")
mcmp.Exec(`SELECT max((select min(id2) from t1)) FROM t2`)

// we need an alias for the subquery so that the id1 = 1 on the inside and the outside look the same and can be merged
mcmp.Exec(`SELECT max((select group_concat(id1, id2) from t1 where id1 = 1)) as x FROM t1 where id1 = 1`)

mcmp.Exec(`SELECT max((select min(id2) from t1 where id2 = 1)) FROM dual`)
mcmp.Exec(`SELECT max((select min(id2) from t1)) FROM t2 where id4 = 7`)

Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (nz *normalizer) walkDownSelect(node, parent SQLNode) bool {
// we should not rewrite the type description
return false
case *AliasedExpr:
// we don't want to rewrite literals in select expressions if the column is not aliased
// we only want to rewrite literals in select expressions if the column is aliased
return node.As.NotEmpty()
}
return nz.err == nil // only continue if we haven't found any errors
Expand Down
28 changes: 13 additions & 15 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func TestSystemVariablesMySQLBelow80(t *testing.T) {

wantQueries := []*querypb.BoundQuery{
{Sql: "select @@sql_mode orig, 'only_full_group_by' new"},
{Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{}},
{Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}

utils.MustMatch(t, wantQueries, sbc1.Queries)
Expand Down Expand Up @@ -220,8 +220,8 @@ func TestSystemVariablesWithSetVarDisabled(t *testing.T) {

wantQueries := []*querypb.BoundQuery{
{Sql: "select @@sql_mode orig, 'only_full_group_by' new"},
{Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{}},
{Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}

utils.MustMatch(t, wantQueries, sbc1.Queries)
Expand Down Expand Up @@ -265,9 +265,9 @@ func TestSetSystemVariablesTx(t *testing.T) {
require.Zero(t, session.ShardSessions)

wantQueries := []*querypb.BoundQuery{
{Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
{Sql: "select @@sql_mode orig, 'only_full_group_by' new"},
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}

utils.MustMatch(t, wantQueries, sbc1.Queries)
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestSetSystemVariables(t *testing.T) {
require.False(t, session.InReservedConn())
wantQueries := []*querypb.BoundQuery{
{Sql: "select @@sql_mode orig, 'only_full_group_by' new"},
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}
utils.MustMatch(t, wantQueries, lookup.Queries)
lookup.Queries = nil
Expand All @@ -310,7 +310,7 @@ func TestSetSystemVariables(t *testing.T) {
require.NoError(t, err)
require.False(t, session.InReservedConn())
wantQueries = []*querypb.BoundQuery{
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ /* comment */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ /* comment */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}
utils.MustMatch(t, wantQueries, lookup.Queries)
lookup.Queries = nil
Expand Down Expand Up @@ -378,8 +378,8 @@ func TestSetSystemVariables(t *testing.T) {

wantQueries = []*querypb.BoundQuery{
{Sql: "select 1 from dual where @@max_tmp_tables != 1"},
{Sql: "set max_tmp_tables = '1', sql_mode = 'only_full_group_by', sql_safe_updates = '0'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "set max_tmp_tables = '1', sql_mode = 'only_full_group_by', sql_safe_updates = '0'", BindVariables: map[string]*querypb.BindVariable{}},
{Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}},
}
utils.MustMatch(t, wantQueries, lookup.Queries)
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestSetSystemVariablesWithReservedConnection(t *testing.T) {
{Sql: "select @@sql_mode orig, '' new"},
{Sql: "set sql_mode = ''"},
{Sql: "select age, city, weight_string(age) from `user` group by age, weight_string(age) order by age asc"},
{Sql: "select age, city + :vtg1 /* INT64 */, weight_string(age) from `user` group by age, weight_string(age) order by age asc", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}},
{Sql: "select age, city + 1, weight_string(age) from `user` group by age, weight_string(age) order by age asc", BindVariables: map[string]*querypb.BindVariable{}},
}
utils.MustMatch(t, wantQueries, sbc1.Queries)
require.Equal(t, "''", session.SystemVariables["sql_mode"])
Expand Down Expand Up @@ -484,9 +484,8 @@ func TestGen4SelectDBA(t *testing.T) {
query, map[string]*querypb.BindVariable{},
)
require.NoError(t, err)
wantQueries = []*querypb.BoundQuery{{Sql: "select :vtg1 /* INT64 */ from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */ and table_name = :table_name1 /* VARCHAR */",
wantQueries = []*querypb.BoundQuery{{Sql: "select 1 from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */ and table_name = :table_name1 /* VARCHAR */",
BindVariables: map[string]*querypb.BindVariable{
"vtg1": sqltypes.Int64BindVariable(1),
"constraint_schema": sqltypes.StringBindVariable("vt_ks"),
"table_name": sqltypes.StringBindVariable("user"),
"__vtschemaname": sqltypes.StringBindVariable("vt_ks"),
Expand All @@ -498,9 +497,8 @@ func TestGen4SelectDBA(t *testing.T) {
query = "select 1 from information_schema.table_constraints where constraint_schema = 'vt_ks'"
_, err = executor.Execute(context.Background(), nil, "TestSelectDBA", NewSafeSession(&vtgatepb.Session{TargetString: "TestExecutor"}), query, map[string]*querypb.BindVariable{})
require.NoError(t, err)
wantQueries = []*querypb.BoundQuery{{Sql: "select :vtg1 /* INT64 */ from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */",
wantQueries = []*querypb.BoundQuery{{Sql: "select 1 from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */",
BindVariables: map[string]*querypb.BindVariable{
"vtg1": sqltypes.Int64BindVariable(1),
"constraint_schema": sqltypes.StringBindVariable("vt_ks"),
"__vtschemaname": sqltypes.StringBindVariable("vt_ks"),
}}}
Expand Down

0 comments on commit 3c92aed

Please sign in to comment.