本文整理汇总了Golang中github.com/pingcap/tidb/ast.RecordSet类的典型用法代码示例。如果您正苦于以下问题:Golang RecordSet类的具体用法?Golang RecordSet怎么用?Golang RecordSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecordSet类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readResult
func readResult(rs ast.RecordSet, count int) {
for count > 0 {
x, err := rs.Next()
if err != nil {
log.Fatal(err)
}
if x == nil {
log.Fatal(count)
}
count--
}
rs.Close()
}
示例2: GetRows
// GetRows gets all the rows from a RecordSet.
func GetRows(rs ast.RecordSet) ([][]types.Datum, error) {
if rs == nil {
return nil, nil
}
var rows [][]types.Datum
defer rs.Close()
// Negative limit means no limit.
for {
row, err := rs.Next()
if err != nil {
return nil, errors.Trace(err)
}
if row == nil {
break
}
rows = append(rows, row.Data)
}
return rows, nil
}
示例3: collectSamples
// collectSamples collects sample from the result set, using Reservoir Sampling algorithm.
// See https://en.wikipedia.org/wiki/Reservoir_sampling
func (e *SimpleExec) collectSamples(result ast.RecordSet) (count int64, samples []*ast.Row, err error) {
for {
var row *ast.Row
row, err = result.Next()
if err != nil {
return count, samples, errors.Trace(err)
}
if row == nil {
break
}
if len(samples) < maxSampleCount {
samples = append(samples, row)
} else {
shouldAdd := rand.Int63n(count) < maxSampleCount
if shouldAdd {
idx := rand.Intn(maxSampleCount)
samples[idx] = row
}
}
count++
}
return count, samples, nil
}