// ProtoToSplitQueryParts transforms a proto3 SplitQueryResponse into // native types func ProtoToSplitQueryParts(sqr *pb.SplitQueryResponse) []SplitQueryPart { if len(sqr.Splits) == 0 { return nil } result := make([]SplitQueryPart, len(sqr.Splits)) for i, split := range sqr.Splits { if split.KeyRangePart != nil { result[i].Query = &KeyRangeQuery{ Sql: string(split.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(split.Query.BindVariables), Keyspace: split.KeyRangePart.Keyspace, KeyRanges: key.ProtoToKeyRanges(split.KeyRangePart.KeyRanges), } } if split.ShardPart != nil { result[i].QueryShard = &QueryShard{ Sql: string(split.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(split.Query.BindVariables), Keyspace: split.ShardPart.Keyspace, Shards: split.ShardPart.Shards, } } result[i].Size = split.Size } return result }
// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest) (response *pb.ExecuteKeyspaceIdsResponse, err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.CallerId, callerid.NewImmediateCallerID("grpc client")) reply := new(proto.QueryResult) executeErr := vtg.server.ExecuteKeyspaceIds(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.Keyspace, key.ProtoToKeyspaceIds(request.KeyspaceIds), request.TabletType, proto.ProtoToSession(request.Session), request.NotInTransaction, reply) response = &pb.ExecuteKeyspaceIdsResponse{ Error: vtgate.VtGateErrorToVtRPCError(executeErr, reply.Error), } if executeErr == nil { response.Result = mproto.QueryResultToProto3(reply.Result) response.Session = proto.SessionToProto(reply.Session) return response, nil } if *vtgate.RPCErrorOnlyInReply { return response, nil } return nil, executeErr }
// StreamExecute is part of the queryservice.QueryServer interface func (q *query) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Query_StreamExecuteServer) (err error) { defer q.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.EffectiveCallerId, request.ImmediateCallerId, ) bv, err := proto.Proto3ToBindVariables(request.Query.BindVariables) if err != nil { return tabletserver.ToGRPCError(err) } if err := q.server.StreamExecute(ctx, request.Target, &proto.Query{ Sql: request.Query.Sql, BindVariables: bv, SessionId: request.SessionId, }, func(reply *mproto.QueryResult) error { result, err := mproto.QueryResultToProto3(reply) if err != nil { return err } return stream.Send(&pb.StreamExecuteResponse{Result: result}) }); err != nil { return tabletserver.ToGRPCError(err) } return nil }
// ExecuteEntityIds is the RPC version of vtgateservice.VTGateService method func (vtg *VTGateP3) ExecuteEntityIds(ctx context.Context, request *pb.ExecuteEntityIdsRequest, response *pb.ExecuteEntityIdsResponse) (err error) { defer vtg.server.HandlePanic(&err) ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout)) defer cancel() ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("bsonp3 client")) reply := new(proto.QueryResult) executeErr := vtg.server.ExecuteEntityIds(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.Keyspace, request.EntityColumnName, request.EntityKeyspaceIds, request.TabletType, proto.ProtoToSession(request.Session), request.NotInTransaction, reply) if executeErr == nil { response.Error = vtgate.RPCErrorToVtRPCError(reply.Err) response.Result = mproto.QueryResultToProto3(reply.Result) response.Session = proto.SessionToProto(reply.Session) } return vterrors.ToJSONError(executeErr) }
// StreamExecuteKeyRanges2 is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGateP3) StreamExecuteKeyRanges2(ctx context.Context, request *pb.StreamExecuteKeyRangesRequest, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("gorpc client")) vtgErr := vtg.server.StreamExecuteKeyRanges(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.Keyspace, request.KeyRanges, request.TabletType, func(reply *proto.QueryResult) error { return sendReply(&pb.StreamExecuteKeyRangesResponse{ Error: vtgate.VtGateErrorToVtRPCError(nil, reply.Error), Result: mproto.QueryResultToProto3(reply.Result), }) }) if vtgErr == nil { return nil } if *vtgate.RPCErrorOnlyInReply { // If there was an app error, send a QueryResult back with it. // Sending back errors this way is not backwards compatible. If a (new) server sends an additional // QueryResult with an error, and the (old) client doesn't know how to read it, it will cause // problems where the client will get out of sync with the number of QueryResults sent. // That's why this the error is only sent this way when the --rpc_errors_only_in_reply flag is set // (signalling that all clients are able to handle new-style errors). return sendReply(&pb.StreamExecuteKeyRangesResponse{ Error: vtgate.VtGateErrorToVtRPCError(vtgErr, ""), }) } return vtgErr }
// StreamExecute is part of the queryservice.QueryServer interface func (q *query) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Query_StreamExecuteServer) (err error) { defer q.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.GetEffectiveCallerId(), request.GetImmediateCallerId(), ) seErr := q.server.StreamExecute(ctx, &proto.Query{ Sql: string(request.Query.Sql), BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables), SessionId: request.SessionId, }, func(reply *mproto.QueryResult) error { return stream.Send(&pb.StreamExecuteResponse{ Result: mproto.QueryResultToProto3(reply), }) }) if seErr != nil { response := &pb.StreamExecuteResponse{ Error: tabletserver.TabletErrorToRPCError(seErr), } if err := stream.Send(response); err != nil { return err } } return nil }
// ExecuteBatch is part of tabletconn.TabletConn // We need to copy the bind variables as tablet server will change them. func (itc *internalTabletConn) ExecuteBatch(ctx context.Context, queries []tproto.BoundQuery, asTransaction bool, transactionID int64) (*tproto.QueryResultList, error) { q := make([]tproto.BoundQuery, len(queries)) for i, query := range queries { bv, err := tproto.BindVariablesToProto3(query.BindVariables) if err != nil { return nil, err } bindVars, err := tproto.Proto3ToBindVariables(bv) if err != nil { return nil, err } q[i].Sql = query.Sql q[i].BindVariables = bindVars } reply := &tproto.QueryResultList{} if err := itc.tablet.qsc.QueryService().ExecuteBatch(ctx, &querypb.Target{ Keyspace: itc.tablet.keyspace, Shard: itc.tablet.shard, TabletType: itc.tablet.tabletType, }, &tproto.QueryList{ Queries: q, AsTransaction: asTransaction, TransactionId: transactionID, }, reply); err != nil { return nil, tabletconn.TabletErrorFromGRPC(tabletserver.ToGRPCError(err)) } return reply, nil }
// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method func (vtg *VTGateP3) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest, response *pb.ExecuteKeyspaceIdsResponse) (err error) { defer vtg.server.HandlePanic(&err) ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout)) defer cancel() ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("gorpc client")) reply := &proto.QueryResult{} vtgErr := vtg.server.ExecuteKeyspaceIds(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.Keyspace, request.KeyspaceIds, request.TabletType, proto.ProtoToSession(request.Session), request.NotInTransaction, reply) response.Error = vtgate.VtGateErrorToVtRPCError(vtgErr, reply.Error) response.Result = mproto.QueryResultToProto3(reply.Result) response.Session = proto.SessionToProto(reply.Session) if *vtgate.RPCErrorOnlyInReply { return nil } return vtgErr }
// StreamExecute is part of tabletconn.TabletConn // We need to copy the bind variables as tablet server will change them. func (itc *internalTabletConn) StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (<-chan *mproto.QueryResult, tabletconn.ErrFunc, error) { bindVars = tproto.Proto3ToBindVariables(tproto.BindVariablesToProto3(bindVars)) result := make(chan *mproto.QueryResult, 10) var finalErr error go func() { finalErr = itc.tablet.qsc.QueryService().StreamExecute(ctx, &pbq.Target{ Keyspace: itc.tablet.keyspace, Shard: itc.tablet.shard, TabletType: itc.tablet.tabletType, }, &tproto.Query{ Sql: query, BindVariables: bindVars, TransactionId: transactionID, }, func(reply *mproto.QueryResult) error { result <- reply return nil }) // the client will only access finalErr after the // channel is closed, and then it's already set. close(result) }() return result, func() error { return tabletconn.TabletErrorFromGRPC(tabletserver.ToGRPCError(finalErr)) }, nil }
// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest) (response *pb.ExecuteKeyspaceIdsResponse, err error) { defer vtg.server.HandlePanic(&err) query := &proto.KeyspaceIdQuery{ Sql: string(request.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables), Keyspace: request.Keyspace, KeyspaceIds: key.ProtoToKeyspaceIds(request.KeyspaceIds), TabletType: topo.ProtoToTabletType(request.TabletType), Session: proto.ProtoToSession(request.Session), NotInTransaction: request.NotInTransaction, } reply := new(proto.QueryResult) executeErr := vtg.server.ExecuteKeyspaceIds(ctx, query, reply) response = &pb.ExecuteKeyspaceIdsResponse{ Error: vtgate.VtGateErrorToVtRPCError(executeErr, reply.Error), } if executeErr == nil { response.Result = mproto.QueryResultToProto3(reply.Result) response.Session = proto.SessionToProto(reply.Session) return response, nil } if *vtgate.RPCErrorOnlyInReply { return response, nil } return nil, executeErr }
// Execute is part of the queryservice.QueryServer interface func (q *query) Execute(ctx context.Context, request *pb.ExecuteRequest) (response *pb.ExecuteResponse, err error) { defer q.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.EffectiveCallerId, request.ImmediateCallerId, ) reply := new(mproto.QueryResult) bv, err := proto.Proto3ToBindVariables(request.Query.BindVariables) if err != nil { return nil, tabletserver.ToGRPCError(err) } if err := q.server.Execute(ctx, request.Target, &proto.Query{ Sql: request.Query.Sql, BindVariables: bv, SessionId: request.SessionId, TransactionId: request.TransactionId, }, reply); err != nil { return nil, tabletserver.ToGRPCError(err) } result, err := mproto.QueryResultToProto3(reply) if err != nil { return nil, tabletserver.ToGRPCError(err) } return &pb.ExecuteResponse{Result: result}, nil }
// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest) (response *pb.ExecuteKeyspaceIdsResponse, err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.CallerId, callerid.NewImmediateCallerID("grpc client")) reply := new(proto.QueryResult) bv, err := tproto.Proto3ToBindVariables(request.Query.BindVariables) if err != nil { return nil, vterrors.ToGRPCError(err) } executeErr := vtg.server.ExecuteKeyspaceIds(ctx, string(request.Query.Sql), bv, request.Keyspace, request.KeyspaceIds, request.TabletType, request.Session, request.NotInTransaction, reply) response = &pb.ExecuteKeyspaceIdsResponse{ Error: vtgate.RPCErrorToVtRPCError(reply.Err), } if executeErr != nil { return nil, vterrors.ToGRPCError(executeErr) } response.Result = sqltypes.ResultToProto3(reply.Result) response.Session = reply.Session return response, nil }
// ProtoToBoundKeyspaceIdQueries transforms a list of BoundKeyspaceIdQuery from proto3 func ProtoToBoundKeyspaceIdQueries(bsq []*pb.BoundKeyspaceIdQuery) []BoundKeyspaceIdQuery { if len(bsq) == 0 { return nil } result := make([]BoundKeyspaceIdQuery, len(bsq)) for i, q := range bsq { result[i].Sql = string(q.Query.Sql) result[i].BindVariables = tproto.Proto3ToBindVariables(q.Query.BindVariables) result[i].Keyspace = q.Keyspace result[i].KeyspaceIds = key.ProtoToKeyspaceIds(q.KeyspaceIds) } return result }
// StreamExecute is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Vitess_StreamExecuteServer) (err error) { defer vtg.server.HandlePanic(&err) query := &proto.Query{ Sql: string(request.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables), TabletType: topo.ProtoToTabletType(request.TabletType), } return vtg.server.StreamExecute(stream.Context(), query, func(value *proto.QueryResult) error { return stream.Send(&pb.StreamExecuteResponse{ Result: mproto.QueryResultToProto3(value.Result), }) }) }
// StreamExecute is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Vitess_StreamExecuteServer) (err error) { defer vtg.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.CallerId, callerid.NewImmediateCallerID("grpc client")) return vtg.server.StreamExecute(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.TabletType, func(value *proto.QueryResult) error { return stream.Send(&pb.StreamExecuteResponse{ Result: mproto.QueryResultToProto3(value.Result), }) }) }
// Execute is part of tabletconn.TabletConn // We need to copy the bind variables as tablet server will change them. func (itc *internalTabletConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (*mproto.QueryResult, error) { bindVars = tproto.Proto3ToBindVariables(tproto.BindVariablesToProto3(bindVars)) reply := &mproto.QueryResult{} if err := itc.tablet.qsc.QueryService().Execute(ctx, &pbq.Target{ Keyspace: itc.tablet.keyspace, Shard: itc.tablet.shard, TabletType: itc.tablet.tabletType, }, &tproto.Query{ Sql: query, BindVariables: bindVars, TransactionId: transactionID, }, reply); err != nil { return nil, tabletconn.TabletErrorFromGRPC(tabletserver.ToGRPCError(err)) } return reply, nil }
// StreamExecute is part of the queryservice.QueryServer interface func (q *query) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Query_StreamExecuteServer) (err error) { defer q.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.EffectiveCallerId, request.ImmediateCallerId, ) return q.server.StreamExecute(ctx, request.Target, &proto.Query{ Sql: string(request.Query.Sql), BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables), SessionId: request.SessionId, }, func(reply *mproto.QueryResult) error { return stream.Send(&pb.StreamExecuteResponse{ Result: mproto.QueryResultToProto3(reply), }) }) }
// Execute is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) Execute(ctx context.Context, request *vtgatepb.ExecuteRequest) (response *vtgatepb.ExecuteResponse, err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.CallerId, callerid.NewImmediateCallerID("grpc client")) bv, err := tproto.Proto3ToBindVariables(request.Query.BindVariables) if err != nil { return nil, vterrors.ToGRPCError(err) } result, err := vtg.server.Execute(ctx, string(request.Query.Sql), bv, request.TabletType, request.Session, request.NotInTransaction) return &vtgatepb.ExecuteResponse{ Result: sqltypes.ResultToProto3(result), Session: request.Session, Error: vterrors.VtRPCErrorFromVtError(err), }, nil }
// StreamExecute is the RPC version of vtgateservice.VTGateService method func (vtg *VTGateP3) StreamExecute(ctx context.Context, request *pb.StreamExecuteRequest, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("bsonp3 client")) vtgErr := vtg.server.StreamExecute(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.TabletType, func(reply *proto.QueryResult) error { return sendReply(&pb.StreamExecuteResponse{ Result: mproto.QueryResultToProto3(reply.Result), }) }) return vterrors.ToJSONError(vtgErr) }
// ProtoToBoundShardQueries transforms a list of BoundShardQuery from proto3 func ProtoToBoundShardQueries(bsq []*vtgatepb.BoundShardQuery) ([]BoundShardQuery, error) { if len(bsq) == 0 { return nil, nil } result := make([]BoundShardQuery, len(bsq)) for i, q := range bsq { result[i].Sql = string(q.Query.Sql) bv, err := tproto.Proto3ToBindVariables(q.Query.BindVariables) if err != nil { return nil, err } result[i].BindVariables = bv result[i].Keyspace = q.Keyspace result[i].Shards = q.Shards } return result, nil }
// SplitQuery is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest) (response *pb.SplitQueryResponse, err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.CallerId, callerid.NewImmediateCallerID("grpc client")) reply := new(proto.SplitQueryResult) if err := vtg.server.SplitQuery(ctx, request.Keyspace, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.SplitColumn, int(request.SplitCount), reply); err != nil { return nil, err } return proto.SplitQueryPartsToProto(reply.Splits), nil }
// StreamExecuteKeyspaceIds is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGate) StreamExecuteKeyspaceIds(request *pb.StreamExecuteKeyspaceIdsRequest, stream pbs.Vitess_StreamExecuteKeyspaceIdsServer) (err error) { defer vtg.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.CallerId, callerid.NewImmediateCallerID("grpc client")) query := &proto.KeyspaceIdQuery{ Sql: string(request.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables), Keyspace: request.Keyspace, KeyspaceIds: key.ProtoToKeyspaceIds(request.KeyspaceIds), TabletType: topo.ProtoToTabletType(request.TabletType), } return vtg.server.StreamExecuteKeyspaceIds(ctx, query, func(value *proto.QueryResult) error { return stream.Send(&pb.StreamExecuteKeyspaceIdsResponse{ Result: mproto.QueryResultToProto3(value.Result), }) }) }
// StreamExecuteKeyRanges is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGateP3) StreamExecuteKeyRanges(ctx context.Context, request *pb.StreamExecuteKeyRangesRequest, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("gorpc client")) return vtg.server.StreamExecuteKeyRanges(ctx, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.Keyspace, key.ProtoToKeyRanges(request.KeyRanges), request.TabletType, func(reply *proto.QueryResult) error { return sendReply(&pb.StreamExecuteKeyRangesResponse{ Error: vtgate.VtGateErrorToVtRPCError(nil, reply.Error), Result: mproto.QueryResultToProto3(reply.Result), }) }) }
// SplitQuery is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest) (response *pb.SplitQueryResponse, err error) { defer vtg.server.HandlePanic(&err) query := &proto.SplitQueryRequest{ Keyspace: request.Keyspace, Query: tproto.BoundQuery{ Sql: string(request.Query.Sql), BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables), }, SplitColumn: request.SplitColumn, SplitCount: int(request.SplitCount), } reply := new(proto.SplitQueryResult) if err := vtg.server.SplitQuery(ctx, query, reply); err != nil { return nil, err } return proto.SplitQueryPartsToProto(reply.Splits), nil }
// Execute is part of the queryservice.QueryServer interface func (q *query) Execute(ctx context.Context, request *pb.ExecuteRequest) (response *pb.ExecuteResponse, err error) { defer q.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.EffectiveCallerId, request.ImmediateCallerId, ) reply := new(mproto.QueryResult) if err := q.server.Execute(ctx, request.Target, &proto.Query{ Sql: string(request.Query.Sql), BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables), SessionId: request.SessionId, TransactionId: request.TransactionId, }, reply); err != nil { return nil, grpc.Errorf(codes.Internal, "%v", err) } return &pb.ExecuteResponse{ Result: mproto.QueryResultToProto3(reply), }, nil }
// SplitQuery is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest) (response *pb.SplitQueryResponse, err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx), request.CallerId, callerid.NewImmediateCallerID("grpc client")) splits, vtgErr := vtg.server.SplitQuery(ctx, request.Keyspace, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.SplitColumn, int(request.SplitCount)) if vtgErr != nil { return nil, vterrors.ToGRPCError(vtgErr) } return &pb.SplitQueryResponse{ Splits: splits, }, nil }
// SplitQuery is the RPC version of vtgateservice.VTGateService method func (vtg *VTGateP3) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest, response *pb.SplitQueryResponse) (err error) { defer vtg.server.HandlePanic(&err) ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout)) defer cancel() ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("bsonp3 client")) splits, vtgErr := vtg.server.SplitQuery(ctx, request.Keyspace, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.SplitColumn, int(request.SplitCount)) if vtgErr != nil { return vterrors.ToJSONError(vtgErr) } response.Splits = splits return nil }
// Execute is part of the queryservice.QueryServer interface func (q *query) Execute(ctx context.Context, request *pb.ExecuteRequest) (response *pb.ExecuteResponse, err error) { defer q.server.HandlePanic(&err) ctx = callinfo.GRPCCallInfo(ctx) reply := new(mproto.QueryResult) execErr := q.server.Execute(ctx, &proto.Query{ Sql: string(request.Query.Sql), BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables), SessionId: request.SessionId, TransactionId: request.TransactionId, }, reply) if execErr != nil { return &pb.ExecuteResponse{ Error: tabletserver.TabletErrorToRPCError(execErr), }, nil } return &pb.ExecuteResponse{ Result: mproto.QueryResultToProto3(reply), }, nil }
// StreamExecute is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) StreamExecute(request *vtgatepb.StreamExecuteRequest, stream vtgateservicepb.Vitess_StreamExecuteServer) (err error) { defer vtg.server.HandlePanic(&err) ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()), request.CallerId, callerid.NewImmediateCallerID("grpc client")) bv, err := tproto.Proto3ToBindVariables(request.Query.BindVariables) if err != nil { return vterrors.ToGRPCError(err) } vtgErr := vtg.server.StreamExecute(ctx, string(request.Query.Sql), bv, request.TabletType, func(value *sqltypes.Result) error { return stream.Send(&vtgatepb.StreamExecuteResponse{ Result: sqltypes.ResultToProto3(value), }) }) return vterrors.ToGRPCError(vtgErr) }
// SplitQuery is the RPC version of vtgateservice.VTGateService method func (vtg *VTGateP3) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest, response *pb.SplitQueryResponse) (err error) { defer vtg.server.HandlePanic(&err) ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout)) defer cancel() ctx = callerid.NewContext(ctx, request.CallerId, callerid.NewImmediateCallerID("gorpc client")) reply := &proto.SplitQueryResult{} vtgErr := vtg.server.SplitQuery(ctx, request.Keyspace, string(request.Query.Sql), tproto.Proto3ToBindVariables(request.Query.BindVariables), request.SplitColumn, int(request.SplitCount), reply) if vtgErr != nil { return vtgErr } *response = *proto.SplitQueryPartsToProto(reply.Splits) return nil }