-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathnil_chunk.go
254 lines (220 loc) · 7.81 KB
/
nil_chunk.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package dynparquet
import (
"io"
"github.com/parquet-go/parquet-go"
"github.com/parquet-go/parquet-go/encoding"
)
// NilColumnChunk is a column chunk that contains a single page with all null
// values of the given type, given length and column index of the parent
// schema. It implements the parquet.ColumnChunk interface.
type NilColumnChunk struct {
typ parquet.Type
columnIndex int
numValues int
}
// NewNilColumnChunk creates a new column chunk configured with the given type,
// column index and number of values in the page.
func NewNilColumnChunk(typ parquet.Type, columnIndex, numValues int) *NilColumnChunk {
return &NilColumnChunk{
typ: typ,
columnIndex: columnIndex,
numValues: numValues,
}
}
// NumValues returns the number of values in the column chunk. Implements the
// parquet.ColumnChunk interface.
func (c *NilColumnChunk) NumValues() int64 {
return int64(c.numValues)
}
// Type returns the type of the column chunk. Implements the
// parquet.ColumnChunk interface.
func (c *NilColumnChunk) Type() parquet.Type {
return c.typ
}
// Type returns the index of the column chunk within the parent schema.
// Implements the parquet.ColumnChunk interface.
func (c *NilColumnChunk) Column() int {
return c.columnIndex
}
// Pages returns an iterator for all pages within the column chunk. This
// iterator will only ever return a single page filled with all null values of
// the configured amount. Implements the parquet.ColumnChunk interface.
func (c *NilColumnChunk) Pages() parquet.Pages {
return &nilPages{
numValues: c.numValues,
columnIndex: c.columnIndex,
typ: c.typ,
}
}
// nilPages is an iterator that will only ever return a single page filled with
// all null values of the configured amount. It knows the column index of the
// schema it belongs to. It implements the parquet.Pages interface.
type nilPages struct {
numValues int
columnIndex int
read bool
seek int
typ parquet.Type
}
// ReadPage returns the next page in the column chunk. It will only ever return
// a single page which returns all null values of the configured amount.
// Implements the parquet.Pages interface.
func (p *nilPages) ReadPage() (parquet.Page, error) {
if p.read {
return nil, io.EOF
}
p.read = true
return &nilPage{
numValues: p.numValues,
columnIndex: p.columnIndex,
seek: p.seek,
typ: p.typ,
}, nil
}
// Close implements the parquet.Pages interface. Since this is a synthetic
// page, it's a no-op.
func (p *nilPages) Close() error {
return nil
}
// nilPage is a page that contains all null values of the configured amount. It
// is aware of the column index of the parent schema it belongs to. It
// implements the parquet.Page interface.
type nilPage struct {
numValues int
columnIndex int
seek int
typ parquet.Type
}
// Column returns the column index of the column in the schema the column
// chunk's page belongs to.
func (p *nilPage) Column() int {
return p.columnIndex
}
// Type returns the type of the column chunk. Implements the
// parquet.ColumnChunk interface.
func (p *nilPage) Type() parquet.Type {
return p.typ
}
// Dictionary returns the dictionary page for the column chunk. Since the page
// only contains null values, the dictionary is always nil.
func (p *nilPage) Dictionary() parquet.Dictionary {
// TODO: Validate that this doesn't require to an empty dictionary of the
// correct type.
return nil
}
// NumRows returns the number of rows the page contains.
func (p *nilPage) NumRows() int64 {
return int64(p.numValues)
}
// NumValues returns the number of values the page contains.
func (p *nilPage) NumValues() int64 {
return int64(p.numValues)
}
// NumNulls returns the number of nulls the page contains.
func (p *nilPage) NumNulls() int64 {
return int64(p.numValues)
}
// Bounds returns the minimum and maximum values of the page, since all values
// in the page are null, both the minimum and maximum values are null.
func (p *nilPage) Bounds() (_, _ parquet.Value, _ bool) {
return parquet.ValueOf(nil).Level(0, 0, p.columnIndex), parquet.ValueOf(nil).Level(0, 0, p.columnIndex), true
}
// Size returns the physical size of the page. Since this page is virtual,
// in-memory and has no real size it returns 0.
func (p *nilPage) Size() int64 {
// TODO: Return the static size of the struct and its fields instead of 0.
// While not strictly necessary, it will make the cumulative size of all
// pages more accurate.
return 0
}
// Values returns an iterator for all values in the page. All reads will return
// null values with the repetition level and definition level set to 0, and the
// appropriate column index configured.
func (p *nilPage) Values() parquet.ValueReader {
return &nilValueReader{
numValues: p.numValues,
idx: p.columnIndex,
read: p.seek,
}
}
// nilValueReader s an iterator for all values in the page. All reads will
// return null values with the repetition level and definition level set to 0,
// and the appropriate column index configured.
type nilValueReader struct {
numValues int
idx int
read int
}
// ReadValues reads the next n values from the page and returns the amount of
// values read. It attempts to write the number of values that the `values`
// parameter can hold. If less values are left to be read than there is space
// for in the `values` parameter, it will return the number of values read and
// an `io.EOF` error. Implements the parquet.ValueReader interface.
func (p *nilValueReader) ReadValues(values []parquet.Value) (int, error) {
i := 0
m := min(len(values), p.numValues-p.read)
for ; i < m; i++ {
values[i] = parquet.ValueOf(nil).Level(0, 0, p.idx)
}
p.read += i
if p.read >= p.numValues {
return i, io.EOF
}
return i, nil
}
// DefinitionLevels returns the definition levels of the page. Since the page
// contains only null values, all of them are 0. Implements the
// parquet.Page interface.
func (p *nilPage) DefinitionLevels() []byte {
return nil
}
// RepetitionLevels returns the definition levels of the page. Since the page
// contains only null values, all of them are 0. Implements the
// parquet.Page interface.
func (p *nilPage) RepetitionLevels() []byte {
return nil
}
// Data is unimplemented, since the page is virtual and does not need to be
// written in its current usage in this package. If that changes this method
// needs to be implemented. Implements the parquet.Page interface.
func (p *nilPage) Data() encoding.Values {
panic("not implemented")
}
func (p *nilPage) Slice(_, _ int64) parquet.Page {
return &nilPage{
numValues: p.numValues,
columnIndex: p.columnIndex,
}
}
// Clone creates a copy of the nilPage. Implements the parquet.Page
// interface.
func (p *nilPage) Clone() parquet.Page {
return &nilPage{
numValues: p.numValues,
columnIndex: p.columnIndex,
}
}
// SeekToRow ensures that any page read is positioned at the given row.
// Implements the parquet.Pages interface.
func (p *nilPages) SeekToRow(row int64) error {
p.seek = int(row)
return nil
}
// ColumnIndex returns the column index of the column chunk. Since the
// NilColumnChunk is a virtual column chunk only for in-memory purposes, it
// returns nil. Implements the parquet.ColumnChunk interface.
func (c *NilColumnChunk) ColumnIndex() (parquet.ColumnIndex, error) {
return nil, nil
}
// OffsetIndex returns the offset index of the column chunk. Since the
// NilColumnChunk is a virtual column chunk only for in-memory purposes, it
// returns nil. Implements the parquet.ColumnChunk interface.
func (c *NilColumnChunk) OffsetIndex() (parquet.OffsetIndex, error) {
return nil, nil
}
// BloomFilter returns the bloomfilter of the column chunk. Since the
// NilColumnChunk is a virtual column chunk only for in-memory purposes, it
// returns nil. Implements the parquet.ColumnChunk interface.
func (c *NilColumnChunk) BloomFilter() parquet.BloomFilter {
return nil
}