vitess.io/vitess@v0.16.2/go/vt/vtgate/engine/vschema_ddl.go (about)

     1  /*
     2  Copyright 2020 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  	"vitess.io/vitess/go/vt/vterrors"
    26  	"vitess.io/vitess/go/vt/vtgate/vindexes"
    27  )
    28  
    29  var _ Primitive = (*AlterVSchema)(nil)
    30  
    31  // AlterVSchema operator applies changes to VSchema
    32  type AlterVSchema struct {
    33  	Keyspace *vindexes.Keyspace
    34  
    35  	AlterVschemaDDL *sqlparser.AlterVschema
    36  
    37  	noTxNeeded
    38  
    39  	noInputs
    40  }
    41  
    42  func (v *AlterVSchema) description() PrimitiveDescription {
    43  	return PrimitiveDescription{
    44  		OperatorType: "AlterVSchema",
    45  		Keyspace:     v.Keyspace,
    46  		Other: map[string]any{
    47  			"query": sqlparser.String(v.AlterVschemaDDL),
    48  		},
    49  	}
    50  }
    51  
    52  // RouteType implements the Primitive interface
    53  func (v *AlterVSchema) RouteType() string {
    54  	return "AlterVSchema"
    55  }
    56  
    57  // GetKeyspaceName implements the Primitive interface
    58  func (v *AlterVSchema) GetKeyspaceName() string {
    59  	return v.Keyspace.Name
    60  }
    61  
    62  // GetTableName implements the Primitive interface
    63  func (v *AlterVSchema) GetTableName() string {
    64  	return v.AlterVschemaDDL.Table.Name.String()
    65  }
    66  
    67  // TryExecute implements the Primitive interface
    68  func (v *AlterVSchema) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable, wantfields bool) (*sqltypes.Result, error) {
    69  	err := vcursor.ExecuteVSchema(ctx, v.Keyspace.Name, v.AlterVschemaDDL)
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  	return &sqltypes.Result{}, nil
    74  }
    75  
    76  // TryStreamExecute implements the Primitive interface
    77  func (v *AlterVSchema) TryStreamExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable, wantfields bool, callback func(*sqltypes.Result) error) error {
    78  	res, err := v.TryExecute(ctx, vcursor, bindVars, wantfields)
    79  	if err != nil {
    80  		return err
    81  	}
    82  	return callback(res)
    83  }
    84  
    85  // GetFields implements the Primitive interface
    86  func (v *AlterVSchema) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*query.BindVariable) (*sqltypes.Result, error) {
    87  	return nil, vterrors.VT13001("GetFields is not supported for AlterVSchema")
    88  }