-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_with_filter_test.go
123 lines (99 loc) · 2.32 KB
/
reader_with_filter_test.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package ethwal
import (
"context"
"errors"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupReaderWithFilterTest(t *testing.T) Indexes[[]int] {
opt := Options{
Dataset: Dataset{
Path: testPath,
},
NewCompressor: NewZSTDCompressor,
NewDecompressor: NewZSTDDecompressor,
NewEncoder: NewCBOREncoder,
NewDecoder: NewCBORDecoder,
FileRollOnClose: true,
}
w, err := NewWriter[[]int](opt)
require.NoError(t, err)
blocks := generateMixedIntBlocks()
for _, block := range blocks {
err := w.Write(context.Background(), block)
require.NoError(t, err)
}
w.Close(context.Background())
indexes := generateMixedIntIndexes()
ib, err := NewIndexer(context.Background(), IndexerOptions[[]int]{
Dataset: opt.Dataset,
Indexes: indexes,
})
require.NoError(t, err)
for _, block := range blocks {
err := ib.Index(context.Background(), block)
require.NoError(t, err)
}
err = ib.Flush(context.Background())
require.NoError(t, err)
return indexes
}
func teardownReaderWithFilterTest() {
_ = os.RemoveAll(testPath)
}
func TestReaderWithFilter(t *testing.T) {
indexes := setupReaderWithFilterTest(t)
defer teardownReaderWithFilterTest()
r, err := NewReader[[]int](Options{
Dataset: Dataset{
Path: testPath,
},
NewDecompressor: NewZSTDDecompressor,
NewDecoder: NewCBORDecoder,
})
require.NoError(t, err)
fb, err := NewFilterBuilder(FilterBuilderOptions[[]int]{
Dataset: Dataset{
Path: testPath,
},
Indexes: indexes,
})
require.NoError(t, err)
r, err = NewReaderWithFilter[[]int](r, fb.Eq("only_even", "true"))
require.NoError(t, err)
for {
block, err := r.Read(context.Background())
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
for _, i := range block.Data {
assert.Equal(t, 0, i%2)
}
}
_ = r.Close()
r, err = NewReader[[]int](Options{
Dataset: Dataset{
Path: testPath,
},
NewDecompressor: NewZSTDDecompressor,
NewDecoder: NewCBORDecoder,
})
require.NoError(t, err)
r, err = NewReaderWithFilter[[]int](r, fb.Eq("only_odd", "true"))
require.NoError(t, err)
for {
block, err := r.Read(context.Background())
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
for _, i := range block.Data {
assert.Equal(t, 1, i%2)
}
}
_ = r.Close()
}