Skip to content

Commit 0306a14

Browse files
test: added more unit test
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
1 parent 40bd899 commit 0306a14

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

go/vt/vtgate/engine/delete_with_input_test.go

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
"github.com/stretchr/testify/require"
2424

2525
"vitess.io/vitess/go/sqltypes"
26+
querypb "vitess.io/vitess/go/vt/proto/query"
2627
"vitess.io/vitess/go/vt/vtgate/vindexes"
2728
)
2829

29-
func TestDeleteWithInput(t *testing.T) {
30+
func TestDeleteWithInputSingleOffset(t *testing.T) {
3031
input := &fakePrimitive{results: []*sqltypes.Result{
3132
sqltypes.MakeTestResult(sqltypes.MakeTestFields("id", "int64"), "1", "2", "3"),
3233
}}
@@ -45,26 +46,71 @@ func TestDeleteWithInput(t *testing.T) {
4546
Query: "dummy_delete",
4647
},
4748
},
49+
OutputCols: []int{0},
4850
}
4951

5052
vc := newDMLTestVCursor("-20", "20-")
51-
_, err := del.TryExecute(context.Background(), vc, nil, false)
53+
_, err := del.TryExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false)
5254
require.NoError(t, err)
5355
vc.ExpectLog(t, []string{
5456
`ResolveDestinations ks [] Destinations:DestinationAllShards()`,
5557
`ExecuteMultiShard ` +
56-
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x89\x02\x011"} values:{type:TUPLE value:"\x89\x02\x012"} values:{type:TUPLE value:"\x89\x02\x013"}} ` +
57-
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x89\x02\x011"} values:{type:TUPLE value:"\x89\x02\x012"} values:{type:TUPLE value:"\x89\x02\x013"}} true false`,
58+
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:INT64 value:"1"} values:{type:INT64 value:"2"} values:{type:INT64 value:"3"}} ` +
59+
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:INT64 value:"1"} values:{type:INT64 value:"2"} values:{type:INT64 value:"3"}} true false`,
5860
})
5961

6062
vc.Rewind()
6163
input.rewind()
62-
err = del.TryStreamExecute(context.Background(), vc, nil, false, func(result *sqltypes.Result) error { return nil })
64+
err = del.TryStreamExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false, func(result *sqltypes.Result) error { return nil })
6365
require.NoError(t, err)
6466
vc.ExpectLog(t, []string{
6567
`ResolveDestinations ks [] Destinations:DestinationAllShards()`,
6668
`ExecuteMultiShard ` +
67-
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x89\x02\x011"} values:{type:TUPLE value:"\x89\x02\x012"} values:{type:TUPLE value:"\x89\x02\x013"}} ` +
68-
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x89\x02\x011"} values:{type:TUPLE value:"\x89\x02\x012"} values:{type:TUPLE value:"\x89\x02\x013"}} true false`,
69+
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:INT64 value:"1"} values:{type:INT64 value:"2"} values:{type:INT64 value:"3"}} ` +
70+
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:INT64 value:"1"} values:{type:INT64 value:"2"} values:{type:INT64 value:"3"}} true false`,
71+
})
72+
}
73+
74+
func TestDeleteWithInputMultiOffset(t *testing.T) {
75+
input := &fakePrimitive{results: []*sqltypes.Result{
76+
sqltypes.MakeTestResult(sqltypes.MakeTestFields("id|col", "int64|varchar"), "1|a", "2|b", "3|c"),
77+
}}
78+
79+
del := &DeleteWithInput{
80+
Input: input,
81+
Delete: &Delete{
82+
DML: &DML{
83+
RoutingParameters: &RoutingParameters{
84+
Opcode: Scatter,
85+
Keyspace: &vindexes.Keyspace{
86+
Name: "ks",
87+
Sharded: true,
88+
},
89+
},
90+
Query: "dummy_delete",
91+
},
92+
},
93+
OutputCols: []int{1, 0},
94+
}
95+
96+
vc := newDMLTestVCursor("-20", "20-")
97+
_, err := del.TryExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false)
98+
require.NoError(t, err)
99+
vc.ExpectLog(t, []string{
100+
`ResolveDestinations ks [] Destinations:DestinationAllShards()`,
101+
`ExecuteMultiShard ` +
102+
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x950\x01a\x89\x02\x011"} values:{type:TUPLE value:"\x950\x01b\x89\x02\x012"} values:{type:TUPLE value:"\x950\x01c\x89\x02\x013"}} ` +
103+
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x950\x01a\x89\x02\x011"} values:{type:TUPLE value:"\x950\x01b\x89\x02\x012"} values:{type:TUPLE value:"\x950\x01c\x89\x02\x013"}} true false`,
104+
})
105+
106+
vc.Rewind()
107+
input.rewind()
108+
err = del.TryStreamExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false, func(result *sqltypes.Result) error { return nil })
109+
require.NoError(t, err)
110+
vc.ExpectLog(t, []string{
111+
`ResolveDestinations ks [] Destinations:DestinationAllShards()`,
112+
`ExecuteMultiShard ` +
113+
`ks.-20: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x950\x01a\x89\x02\x011"} values:{type:TUPLE value:"\x950\x01b\x89\x02\x012"} values:{type:TUPLE value:"\x950\x01c\x89\x02\x013"}} ` +
114+
`ks.20-: dummy_delete {dm_vals: type:TUPLE values:{type:TUPLE value:"\x950\x01a\x89\x02\x011"} values:{type:TUPLE value:"\x950\x01b\x89\x02\x012"} values:{type:TUPLE value:"\x950\x01c\x89\x02\x013"}} true false`,
69115
})
70116
}

go/vt/vtgate/executor_dml_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ func TestDeleteMultiTable(t *testing.T) {
30313031

30323032
var dmlVals []*querypb.Value
30333033
for i := 0; i < 8; i++ {
3034-
dmlVals = append(dmlVals, sqltypes.TupleToProto([]sqltypes.Value{sqltypes.TestValue(sqltypes.Int32, "1")}))
3034+
dmlVals = append(dmlVals, sqltypes.ValueToProto(sqltypes.NewInt32(1)))
30353035
}
30363036

30373037
bq := &querypb.BoundQuery{
@@ -3041,14 +3041,14 @@ func TestDeleteMultiTable(t *testing.T) {
30413041
wantQueries := []*querypb.BoundQuery{
30423042
{Sql: "select `user`.id, `user`.col from `user`", BindVariables: map[string]*querypb.BindVariable{}},
30433043
bq, bq, bq, bq, bq, bq, bq, bq,
3044-
{Sql: "select `user`.Id, `user`.`name` from `user` where (`user`.id) in ::dm_vals for update", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
3045-
{Sql: "delete from `user` where (`user`.id) in ::dm_vals", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}}}
3044+
{Sql: "select `user`.Id, `user`.`name` from `user` where `user`.id in ::dm_vals for update", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
3045+
{Sql: "delete from `user` where `user`.id in ::dm_vals", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}}}
30463046
assertQueries(t, sbc1, wantQueries)
30473047

30483048
wantQueries = []*querypb.BoundQuery{
30493049
{Sql: "select `user`.id, `user`.col from `user`", BindVariables: map[string]*querypb.BindVariable{}},
3050-
{Sql: "select `user`.Id, `user`.`name` from `user` where (`user`.id) in ::dm_vals for update", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
3051-
{Sql: "delete from `user` where (`user`.id) in ::dm_vals", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
3050+
{Sql: "select `user`.Id, `user`.`name` from `user` where `user`.id in ::dm_vals for update", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
3051+
{Sql: "delete from `user` where `user`.id in ::dm_vals", BindVariables: map[string]*querypb.BindVariable{"dm_vals": {Type: querypb.Type_TUPLE, Values: dmlVals}}},
30523052
}
30533053
assertQueries(t, sbc2, wantQueries)
30543054

0 commit comments

Comments
 (0)