本文整理汇总了Golang中github.com/pingcap/tidb/kv.Client.Send方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Send方法的具体用法?Golang Client.Send怎么用?Golang Client.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/kv.Client
的用法示例。
在下文中一共展示了Client.Send方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Select
// Select do a select request, returns SelectResult.
// conncurrency: The max concurrency for underlying coprocessor request.
// keepOrder: If the result should returned in key order. For example if we need keep data in order by
// scan index, we should set keepOrder to true.
func Select(client kv.Client, req *tipb.SelectRequest, concurrency int, keepOrder bool) (SelectResult, error) {
// Convert tipb.*Request to kv.Request.
kvReq, err := composeRequest(req, concurrency, keepOrder)
if err != nil {
return nil, errors.Trace(err)
}
resp := client.Send(kvReq)
if resp == nil {
return nil, errors.New("client returns nil response")
}
result := &selectResult{
resp: resp,
results: make(chan PartialResult, 5),
done: make(chan error, 1),
}
// If Aggregates is not nil, we should set result fields latter.
if len(req.Aggregates) == 0 && len(req.GroupBy) == 0 {
if req.TableInfo != nil {
result.fields = ProtoColumnsToFieldTypes(req.TableInfo.Columns)
} else {
result.fields = ProtoColumnsToFieldTypes(req.IndexInfo.Columns)
length := len(req.IndexInfo.Columns)
if req.IndexInfo.Columns[length-1].GetPkHandle() {
// Returned index row do not contains extra PKHandle column.
result.fields = result.fields[:length-1]
}
result.index = true
}
} else {
result.aggregate = true
}
return result, nil
}
示例2: Select
// Select do a select request, returns SelectResult.
// conncurrency: The max concurrency for underlying coprocessor request.
// keepOrder: If the result should returned in key order. For example if we need keep data in order by
// scan index, we should set keepOrder to true.
func Select(client kv.Client, req *tipb.SelectRequest, keyRanges []kv.KeyRange, concurrency int, keepOrder bool) (SelectResult, error) {
var err error
startTs := time.Now()
defer func() {
// Add metrics
queryHistgram.Observe(time.Since(startTs).Seconds())
if err != nil {
queryCounter.WithLabelValues(queryFailed).Inc()
} else {
queryCounter.WithLabelValues(querySucc).Inc()
}
}()
// Convert tipb.*Request to kv.Request.
kvReq, err1 := composeRequest(req, keyRanges, concurrency, keepOrder)
if err1 != nil {
err = errors.Trace(err1)
return nil, err
}
resp := client.Send(kvReq)
if resp == nil {
err = errors.New("client returns nil response")
return nil, err
}
result := &selectResult{
resp: resp,
results: make(chan PartialResult, 5),
done: make(chan error, 1),
closed: make(chan struct{}),
}
// If Aggregates is not nil, we should set result fields latter.
if len(req.Aggregates) == 0 && len(req.GroupBy) == 0 {
if req.TableInfo != nil {
result.fields = ProtoColumnsToFieldTypes(req.TableInfo.Columns)
} else {
result.fields = ProtoColumnsToFieldTypes(req.IndexInfo.Columns)
length := len(req.IndexInfo.Columns)
if req.IndexInfo.Columns[length-1].GetPkHandle() {
// Returned index row do not contains extra PKHandle column.
result.fields = result.fields[:length-1]
}
result.index = true
}
} else {
result.aggregate = true
}
return result, nil
}
示例3: Select
// Select do a select request, returns SelectResult.
func Select(client kv.Client, req *tipb.SelectRequest, concurrency int) (*SelectResult, error) {
// Convert tipb.*Request to kv.Request
kvReq, err := composeRequest(req, concurrency)
if err != nil {
return nil, errors.Trace(err)
}
resp := client.Send(kvReq)
if resp == nil {
return nil, errors.New("client returns nil response")
}
var columns []*tipb.ColumnInfo
if req.TableInfo != nil {
columns = req.TableInfo.Columns
} else {
columns = req.IndexInfo.Columns
}
fields := tablecodec.ProtoColumnsToFieldTypes(columns)
return &SelectResult{fields: fields, resp: resp}, nil
}
示例4: Select
// Select do a select request, returns SelectResult.
func Select(client kv.Client, req *tipb.SelectRequest, concurrency int) (*SelectResult, error) {
// Convert tipb.*Request to kv.Request
kvReq, err := composeRequest(req, concurrency)
if err != nil {
return nil, errors.Trace(err)
}
resp := client.Send(kvReq)
if resp == nil {
return nil, errors.New("client returns nil response")
}
result := &SelectResult{resp: resp}
// If Aggregates is not nil, we should set result fields latter.
if len(req.Aggregates) == 0 && len(req.GroupBy) == 0 {
if req.TableInfo != nil {
result.fields = ProtoColumnsToFieldTypes(req.TableInfo.Columns)
} else {
result.fields = ProtoColumnsToFieldTypes(req.IndexInfo.Columns)
result.index = true
}
} else {
result.aggregate = true
}
return result, nil
}