-
Notifications
You must be signed in to change notification settings - Fork 67
/
reader.go
45 lines (42 loc) · 1001 Bytes
/
reader.go
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
34
35
36
37
38
39
40
41
42
43
44
45
package parquetio
import (
"context"
"errors"
"io"
"github.com/apache/arrow/go/v14/arrow/memory"
"github.com/apache/arrow/go/v14/parquet"
"github.com/apache/arrow/go/v14/parquet/file"
"github.com/apache/arrow/go/v14/parquet/pqarrow"
"github.com/brimdata/zed"
"github.com/brimdata/zed/zio/arrowio"
)
func NewReader(zctx *zed.Context, r io.Reader) (*arrowio.Reader, error) {
ras, ok := r.(parquet.ReaderAtSeeker)
if !ok {
return nil, errors.New("reader cannot seek")
}
pr, err := file.NewParquetReader(ras)
if err != nil {
return nil, err
}
props := pqarrow.ArrowReadProperties{
Parallel: true,
BatchSize: 256 * 1024,
}
fr, err := pqarrow.NewFileReader(pr, props, memory.DefaultAllocator)
if err != nil {
pr.Close()
return nil, err
}
rr, err := fr.GetRecordReader(context.TODO(), nil, nil)
if err != nil {
pr.Close()
return nil, err
}
ar, err := arrowio.NewReaderFromRecordReader(zctx, rr)
if err != nil {
pr.Close()
return nil, err
}
return ar, nil
}