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

     1  /*
     2  Copyright 2021 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/key"
    24  	querypb "vitess.io/vitess/go/vt/proto/query"
    25  	"vitess.io/vitess/go/vt/vterrors"
    26  	"vitess.io/vitess/go/vt/vtgate/vindexes"
    27  )
    28  
    29  var _ Primitive = (*MStream)(nil)
    30  
    31  // MStream is an operator for message streaming from specific keyspace, destination
    32  type MStream struct {
    33  	// Keyspace specifies the keyspace to stream messages from
    34  	Keyspace *vindexes.Keyspace
    35  
    36  	// TargetDestination specifies an explicit target destination to stream messages from
    37  	TargetDestination key.Destination
    38  
    39  	// TableName specifies the table on which stream will be executed.
    40  	TableName string
    41  
    42  	noTxNeeded
    43  
    44  	noInputs
    45  }
    46  
    47  // RouteType implements the Primitive interface
    48  func (m *MStream) RouteType() string {
    49  	return "MStream"
    50  }
    51  
    52  // GetKeyspaceName implements the Primitive interface
    53  func (m *MStream) GetKeyspaceName() string {
    54  	return m.Keyspace.Name
    55  }
    56  
    57  // GetTableName implements the Primitive interface
    58  func (m *MStream) GetTableName() string {
    59  	return m.TableName
    60  }
    61  
    62  // TryExecute implements the Primitive interface
    63  func (m *MStream) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
    64  	return nil, vterrors.VT13001("TryExecute is not supported for MStream")
    65  }
    66  
    67  // TryStreamExecute implements the Primitive interface
    68  func (m *MStream) TryStreamExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool, callback func(*sqltypes.Result) error) error {
    69  	rss, _, err := vcursor.ResolveDestinations(ctx, m.Keyspace.Name, nil, []key.Destination{m.TargetDestination})
    70  	if err != nil {
    71  		return err
    72  	}
    73  	return vcursor.MessageStream(ctx, rss, m.TableName, callback)
    74  }
    75  
    76  // GetFields implements the Primitive interface
    77  func (m *MStream) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
    78  	return nil, vterrors.VT13001("GetFields is not supported for MStream")
    79  }
    80  
    81  func (m *MStream) description() PrimitiveDescription {
    82  	return PrimitiveDescription{
    83  		OperatorType:      "MStream",
    84  		Keyspace:          m.Keyspace,
    85  		TargetDestination: m.TargetDestination,
    86  
    87  		Other: map[string]any{"Table": m.TableName},
    88  	}
    89  }