From 87d1fe894d3b834f3ce73068155af5d868c125b2 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 31 Mar 2020 07:46:19 +0200 Subject: [PATCH] Minor fixes Signed-off-by: Andres Taylor --- go/vt/vtgate/engine/send.go | 24 ++++++++++++++++++- go/vt/vtgate/executor.go | 2 -- go/vt/vtgate/executor_test.go | 1 - .../planbuilder/testdata/bypass_cases.txt | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/go/vt/vtgate/engine/send.go b/go/vt/vtgate/engine/send.go index 7bd8bc9c77d..8a8d0a880fb 100644 --- a/go/vt/vtgate/engine/send.go +++ b/go/vt/vtgate/engine/send.go @@ -1,6 +1,8 @@ package engine import ( + "encoding/json" + "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/key" "vitess.io/vitess/go/vt/proto/query" @@ -31,6 +33,26 @@ type Send struct { noInputs } +// MarshalJSON serializes the Send into a JSON representation. +// It's used for testing and diagnostics. +func (s *Send) MarshalJSON() ([]byte, error) { + marshalSend := struct { + Opcode string + Keyspace *vindexes.Keyspace + TargetDestination key.Destination + Query string + NoAutoCommit bool + }{ + Opcode: "Send", + Keyspace: s.Keyspace, + TargetDestination: s.TargetDestination, + NoAutoCommit: s.NoAutoCommit, + Query: s.Query, + } + + return json.Marshal(marshalSend) +} + // RouteType implements Primitive interface func (s *Send) RouteType() string { if s.NoAutoCommit { @@ -90,5 +112,5 @@ func (s *Send) StreamExecute(vcursor VCursor, bindVars map[string]*query.BindVar // GetFields implements Primitive interface func (s *Send) GetFields(vcursor VCursor, bindVars map[string]*query.BindVariable) (*sqltypes.Result, error) { - return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "not reachable") // TODO: systay - @sugu, is this correct? + return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "not reachable") } diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 9da0a08c418..3535022cd9f 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -266,8 +266,6 @@ func (e *Executor) execute(ctx context.Context, safeSession *SafeSession, sql st } func (e *Executor) handleExec(ctx context.Context, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable, logStats *LogStats, stmtType sqlparser.StatementType) (*sqltypes.Result, error) { - - // V3 mode. query, comments := sqlparser.SplitMarginComments(sql) vcursor, _ := newVCursorImpl(ctx, safeSession, comments, e, logStats, e.VSchema(), e.resolver.resolver) plan, err := e.getPlan( diff --git a/go/vt/vtgate/executor_test.go b/go/vt/vtgate/executor_test.go index 6c1a690d143..938f4340843 100644 --- a/go/vt/vtgate/executor_test.go +++ b/go/vt/vtgate/executor_test.go @@ -194,7 +194,6 @@ func TestExecutorTransactionsNoAutoCommit(t *testing.T) { } } -//TODO - what about these? func TestDirectTargetRewrites(t *testing.T) { executor, _, _, sbclookup := createExecutorEnv() executor.normalize = true diff --git a/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt b/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt index 672bbc87f1d..e68e934d78a 100644 --- a/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt @@ -3,6 +3,7 @@ { "Original": "select count(*), col from unsharded", "Instructions": { + "Opcode": "Send", "Keyspace": { "Name": "main", "Sharded": false @@ -18,6 +19,7 @@ { "Original": "update user set val = 1 where id = 18446744073709551616 and id = 1", "Instructions": { + "Opcode": "Send", "Keyspace": { "Name": "main", "Sharded": false @@ -33,6 +35,7 @@ { "Original": "DELETE FROM USER WHERE ID = 42", "Instructions": { + "Opcode": "Send", "Keyspace": { "Name": "main", "Sharded": false @@ -48,6 +51,7 @@ { "Original": "INSERT INTO USER (ID, NAME) VALUES (42, 'ms X')", "Instructions": { + "Opcode": "Send", "Keyspace": { "Name": "main", "Sharded": false