vitess.io/vitess@v0.16.2/go/vt/vtgate/engine/show_exec.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package engine 18 19 import ( 20 "context" 21 22 "vitess.io/vitess/go/sqltypes" 23 "vitess.io/vitess/go/vt/proto/query" 24 "vitess.io/vitess/go/vt/sqlparser" 25 ) 26 27 var _ Primitive = (*ShowExec)(nil) 28 29 // ShowExec is a primitive to call into executor via vcursor. 30 type ShowExec struct { 31 Command sqlparser.ShowCommandType 32 ShowFilter *sqlparser.ShowFilter 33 34 noInputs 35 noTxNeeded 36 } 37 38 func (s *ShowExec) RouteType() string { 39 return "ShowExec" 40 } 41 42 func (s *ShowExec) GetKeyspaceName() string { 43 return "" 44 } 45 46 func (s *ShowExec) GetTableName() string { 47 return "" 48 } 49 50 func (s *ShowExec) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable) (*sqltypes.Result, error) { 51 qr, err := s.TryExecute(ctx, vcursor, bindVars, true) 52 if err != nil { 53 return nil, err 54 } 55 qr.Rows = nil 56 return qr, nil 57 } 58 59 func (s *ShowExec) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable, wantfields bool) (*sqltypes.Result, error) { 60 return vcursor.ShowExec(ctx, s.Command, s.ShowFilter) 61 } 62 63 func (s *ShowExec) TryStreamExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable, wantfields bool, callback func(*sqltypes.Result) error) error { 64 qr, err := s.TryExecute(ctx, vcursor, bindVars, wantfields) 65 if err != nil { 66 return err 67 } 68 return callback(qr) 69 } 70 71 func (s *ShowExec) description() PrimitiveDescription { 72 other := map[string]any{} 73 if s.ShowFilter != nil { 74 other["Filter"] = sqlparser.String(s.ShowFilter) 75 } 76 return PrimitiveDescription{ 77 OperatorType: "ShowExec", 78 Variant: s.Command.ToString(), 79 Other: other, 80 } 81 }