本文整理汇总了Golang中github.com/youtube/vitess/go/vt/key.ProtoToKeyRanges函数的典型用法代码示例。如果您正苦于以下问题:Golang ProtoToKeyRanges函数的具体用法?Golang ProtoToKeyRanges怎么用?Golang ProtoToKeyRanges使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ProtoToKeyRanges函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ProtoToSplitQueryParts
// 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
}
示例2: ExecuteKeyRanges
// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *pb.ExecuteKeyRangesRequest) (response *pb.ExecuteKeyRangesResponse, 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.ExecuteKeyRanges(ctx,
string(request.Query.Sql),
tproto.Proto3ToBindVariables(request.Query.BindVariables),
request.Keyspace,
key.ProtoToKeyRanges(request.KeyRanges),
request.TabletType,
proto.ProtoToSession(request.Session),
request.NotInTransaction,
reply)
response = &pb.ExecuteKeyRangesResponse{
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
}
示例3: ExecuteKeyRanges
func (conn *vtgateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*pb.KeyRange, bindVars map[string]interface{}, tabletType pb.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
var s *proto.Session
if session != nil {
s = session.(*proto.Session)
}
request := proto.KeyRangeQuery{
CallerID: getEffectiveCallerID(ctx),
Sql: query,
BindVariables: bindVars,
Keyspace: keyspace,
KeyRanges: key.ProtoToKeyRanges(keyRanges),
TabletType: topo.ProtoToTabletType(tabletType),
Session: s,
NotInTransaction: notInTransaction,
}
var result proto.QueryResult
if err := conn.rpcConn.Call(ctx, "VTGate.ExecuteKeyRanges", request, &result); err != nil {
return nil, session, err
}
if result.Error != "" {
return nil, result.Session, errors.New(result.Error)
}
if err := vterrors.FromRPCError(result.Err); err != nil {
return nil, result.Session, err
}
return result.Result, result.Session, nil
}
示例4: ExecuteKeyRanges
// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *pb.ExecuteKeyRangesRequest) (response *pb.ExecuteKeyRangesResponse, err error) {
defer vtg.server.HandlePanic(&err)
query := &proto.KeyRangeQuery{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
Keyspace: request.Keyspace,
KeyRanges: key.ProtoToKeyRanges(request.KeyRanges),
TabletType: topo.ProtoToTabletType(request.TabletType),
Session: proto.ProtoToSession(request.Session),
NotInTransaction: request.NotInTransaction,
}
reply := new(proto.QueryResult)
executeErr := vtg.server.ExecuteKeyRanges(ctx, query, reply)
response = &pb.ExecuteKeyRangesResponse{
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
}
示例5: StreamExecuteKeyRanges2
// 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,
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),
})
})
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
}
示例6: StreamExecuteKeyRanges2
func (conn *vtgateConn) StreamExecuteKeyRanges2(ctx context.Context, query string, keyspace string, keyRanges []*pb.KeyRange, bindVars map[string]interface{}, tabletType pb.TabletType) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) {
req := &proto.KeyRangeQuery{
CallerID: getEffectiveCallerID(ctx),
Sql: query,
BindVariables: bindVars,
Keyspace: keyspace,
KeyRanges: key.ProtoToKeyRanges(keyRanges),
TabletType: topo.ProtoToTabletType(tabletType),
Session: nil,
}
sr := make(chan *proto.QueryResult, 10)
c := conn.rpcConn.StreamGo("VTGate.StreamExecuteKeyRanges2", req, sr)
return sendStreamResults(c, sr)
}
示例7: StreamExecuteKeyRanges
// StreamExecuteKeyRanges is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecuteKeyRanges(request *pb.StreamExecuteKeyRangesRequest, stream pbs.Vitess_StreamExecuteKeyRangesServer) (err error) {
defer vtg.server.HandlePanic(&err)
query := &proto.KeyRangeQuery{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
Keyspace: request.Keyspace,
KeyRanges: key.ProtoToKeyRanges(request.KeyRanges),
TabletType: topo.ProtoToTabletType(request.TabletType),
}
return vtg.server.StreamExecuteKeyRanges(stream.Context(), query, func(value *proto.QueryResult) error {
return stream.Send(&pb.StreamExecuteKeyRangesResponse{
Result: mproto.QueryResultToProto3(value.Result),
})
})
}
示例8: StreamExecuteKeyRanges
// StreamExecuteKeyRanges is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecuteKeyRanges(request *pb.StreamExecuteKeyRangesRequest, stream pbs.Vitess_StreamExecuteKeyRangesServer) (err error) {
defer vtg.server.HandlePanic(&err)
ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
return vtg.server.StreamExecuteKeyRanges(ctx,
string(request.Query.Sql),
tproto.Proto3ToBindVariables(request.Query.BindVariables),
request.Keyspace,
key.ProtoToKeyRanges(request.KeyRanges),
request.TabletType,
func(value *proto.QueryResult) error {
return stream.Send(&pb.StreamExecuteKeyRangesResponse{
Result: mproto.QueryResultToProto3(value.Result),
})
})
}