本文整理匯總了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
}