diff --git a/go/vt/vtgate/engine/send.go b/go/vt/vtgate/engine/send.go index c812fa53ac5..1934b9f6743 100644 --- a/go/vt/vtgate/engine/send.go +++ b/go/vt/vtgate/engine/send.go @@ -141,13 +141,12 @@ func (s *Send) StreamExecute(vcursor VCursor, bindVars map[string]*querypb.BindV // GetFields implements Primitive interface func (s *Send) GetFields(vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) { - // We don't need to worry about GetFields being needed for joins since the Send primitive currently doesn't - // get nested with other types of primitives. - // However, GetFields is used for prepared statements. Because of that, prepared statements are not yet - // compatible with the Send primitive. - // - // TODO: implement this - return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "not reachable") + qr, err := s.Execute(vcursor, bindVars, false) + if err != nil { + return nil, vterrors.Wrap(err, "sendGetFields") + } + qr.Rows = nil + return qr, nil } func (s *Send) description() PrimitiveDescription { diff --git a/go/vt/vtgate/engine/send_test.go b/go/vt/vtgate/engine/send_test.go index 162018aac23..a0423e9dfd5 100644 --- a/go/vt/vtgate/engine/send_test.go +++ b/go/vt/vtgate/engine/send_test.go @@ -20,6 +20,8 @@ import ( "errors" "testing" + "vitess.io/vitess/go/sqltypes" + "github.com/stretchr/testify/require" "vitess.io/vitess/go/vt/key" @@ -264,3 +266,34 @@ func TestSendTable_StreamExecute(t *testing.T) { }) } } + +func TestSendGetFields(t *testing.T) { + results := []*sqltypes.Result{sqltypes.MakeTestResult( + sqltypes.MakeTestFields( + "id|c1|c2|c3", + "int64|int64|int64|int64", + ), + "1|4|5|6", + "2|7|8|9", + )} + + send := &Send{ + Keyspace: &vindexes.Keyspace{ + Name: "ks", + Sharded: true, + }, + Query: "dummy_query", + TargetDestination: key.DestinationAllShards{}, + IsDML: true, + SingleShardOnly: false, + } + vc := &loggingVCursor{shards: []string{"-20", "20-"}, results: results} + qr, err := send.GetFields(vc, map[string]*querypb.BindVariable{}) + require.NoError(t, err) + vc.ExpectLog(t, []string{ + `ResolveDestinations ks [] Destinations:DestinationAllShards()`, + `ExecuteMultiShard ks.-20: dummy_query {} ks.20-: dummy_query {} true false`, + }) + require.Nil(t, qr.Rows) + require.Equal(t, 4, len(qr.Fields)) +}