-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathplugin_read.go
More file actions
33 lines (28 loc) · 818 Bytes
/
plugin_read.go
File metadata and controls
33 lines (28 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package plugin
import (
"context"
"github.com/apache/arrow-go/v18/arrow"
"github.com/cloudquery/plugin-sdk/v4/schema"
)
// readAll is used in tests to read all records from a table.
func (p *Plugin) readAll(ctx context.Context, table *schema.Table) ([]arrow.RecordBatch, error) {
var err error
ch := make(chan arrow.RecordBatch)
go func() {
defer close(ch)
err = p.client.Read(ctx, table, ch)
}()
// nolint:prealloc
var records []arrow.RecordBatch
for record := range ch {
records = append(records, sliceToSingleRowRecord(record)...)
}
return records, err
}
func sliceToSingleRowRecord(record arrow.RecordBatch) []arrow.RecordBatch {
result := make([]arrow.RecordBatch, record.NumRows())
for i := int64(0); i < record.NumRows(); i++ {
result[i] = record.NewSlice(i, i+1)
}
return result
}