-
Notifications
You must be signed in to change notification settings - Fork 65
/
testing.go
69 lines (56 loc) 路 1.37 KB
/
testing.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package query
import (
"context"
"errors"
"fmt"
"github.com/apache/arrow/go/v16/arrow"
"github.com/apache/arrow/go/v16/arrow/memory"
"github.com/polarsignals/frostdb/dynparquet"
"github.com/polarsignals/frostdb/query/logicalplan"
)
type FakeTableReader struct {
Records []arrow.Record
FrostdbSchema *dynparquet.Schema
}
func (r *FakeTableReader) View(ctx context.Context, fn func(ctx context.Context, tx uint64) error) error {
return fn(ctx, 0)
}
func (r *FakeTableReader) Iterator(
ctx context.Context,
_ uint64,
_ memory.Allocator,
callbacks []logicalplan.Callback,
_ ...logicalplan.Option,
) error {
if len(callbacks) == 0 {
return errors.New("no callbacks provided")
}
for i, r := range r.Records {
cb := callbacks[i%len(callbacks)]
if err := cb(ctx, r); err != nil {
return err
}
}
return nil
}
func (r *FakeTableReader) SchemaIterator(
_ context.Context,
_ uint64,
_ memory.Allocator,
_ []logicalplan.Callback,
_ ...logicalplan.Option,
) error {
return errors.New("not implemented")
}
func (r *FakeTableReader) Schema() *dynparquet.Schema {
return r.FrostdbSchema
}
type FakeTableProvider struct {
Tables map[string]logicalplan.TableReader
}
func (f *FakeTableProvider) GetTable(name string) (logicalplan.TableReader, error) {
if t, ok := f.Tables[name]; ok {
return t, nil
}
return nil, fmt.Errorf("table %s not found", name)
}