vitess.io/vitess@v0.16.2/go/vt/vtgate/engine/shard_route.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  	querypb "vitess.io/vitess/go/vt/proto/query"
    24  	"vitess.io/vitess/go/vt/srvtopo"
    25  	"vitess.io/vitess/go/vt/vterrors"
    26  )
    27  
    28  var _ StreamExecutor = (*shardRoute)(nil)
    29  
    30  // shardRoute is an internal primitive used by Route
    31  // for performing merge sorts.
    32  type shardRoute struct {
    33  	query     string
    34  	rs        *srvtopo.ResolvedShard
    35  	bv        map[string]*querypb.BindVariable
    36  	primitive Primitive
    37  }
    38  
    39  // StreamExecute performs a streaming exec.
    40  func (sr *shardRoute) StreamExecute(ctx context.Context, vcursor VCursor, _ map[string]*querypb.BindVariable, _ bool, callback func(*sqltypes.Result) error) error {
    41  	// TODO rollback on error and autocommit should probably not be used like this
    42  	errors := vcursor.StreamExecuteMulti(ctx, sr.primitive, sr.query, []*srvtopo.ResolvedShard{sr.rs}, []map[string]*querypb.BindVariable{sr.bv}, false /* rollbackOnError */, false /* autocommit */, callback)
    43  	return vterrors.Aggregate(errors)
    44  }