This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
page_header.go
221 lines (173 loc) · 5.52 KB
/
page_header.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
package parquet
import (
"fmt"
"github.com/segmentio/parquet-go/format"
)
// PageHeader is an interface implemented by parquet page headers.
type PageHeader interface {
// Returns the number of values in the page (including nulls).
NumValues() int64
// Returns the page encoding.
Encoding() format.Encoding
// Returns the parquet format page type.
PageType() format.PageType
}
// DataPageHeader is a specialization of the PageHeader interface implemented by
// data pages.
type DataPageHeader interface {
PageHeader
// Returns the encoding of the repetition level section.
RepetitionLevelEncoding() format.Encoding
// Returns the encoding of the definition level section.
DefinitionLevelEncoding() format.Encoding
// Returns the number of null values in the page.
NullCount() int64
// Returns the minimum value in the page based on the ordering rules of the
// column's logical type.
//
// As an optimization, the method may return the same slice across multiple
// calls. Programs must treat the returned value as immutable to prevent
// unpredictable behaviors.
//
// If the page only contains only null values, an empty slice is returned.
MinValue() []byte
// Returns the maximum value in the page based on the ordering rules of the
// column's logical type.
//
// As an optimization, the method may return the same slice across multiple
// calls. Programs must treat the returned value as immutable to prevent
// unpredictable behaviors.
//
// If the page only contains only null values, an empty slice is returned.
MaxValue() []byte
}
// DictionaryPageHeader is an implementation of the PageHeader interface
// representing dictionary pages.
type DictionaryPageHeader struct {
header *format.DictionaryPageHeader
}
func (dict DictionaryPageHeader) NumValues() int64 {
return int64(dict.header.NumValues)
}
func (dict DictionaryPageHeader) Encoding() format.Encoding {
return dict.header.Encoding
}
func (dict DictionaryPageHeader) PageType() format.PageType {
return format.DictionaryPage
}
func (dict DictionaryPageHeader) IsSorted() bool {
return dict.header.IsSorted
}
func (dict DictionaryPageHeader) String() string {
return fmt.Sprintf("DICTIONARY_PAGE_HEADER{NumValues=%d,Encoding=%s,IsSorted=%t}",
dict.header.NumValues,
dict.header.Encoding,
dict.header.IsSorted)
}
// DataPageHeaderV1 is an implementation of the DataPageHeader interface
// representing data pages version 1.
type DataPageHeaderV1 struct {
header *format.DataPageHeader
}
func (v1 DataPageHeaderV1) NumValues() int64 {
return int64(v1.header.NumValues)
}
func (v1 DataPageHeaderV1) RepetitionLevelEncoding() format.Encoding {
return v1.header.RepetitionLevelEncoding
}
func (v1 DataPageHeaderV1) DefinitionLevelEncoding() format.Encoding {
return v1.header.DefinitionLevelEncoding
}
func (v1 DataPageHeaderV1) Encoding() format.Encoding {
return v1.header.Encoding
}
func (v1 DataPageHeaderV1) PageType() format.PageType {
return format.DataPage
}
func (v1 DataPageHeaderV1) NullCount() int64 {
return v1.header.Statistics.NullCount
}
func (v1 DataPageHeaderV1) MinValue() []byte {
return v1.header.Statistics.MinValue
}
func (v1 DataPageHeaderV1) MaxValue() []byte {
return v1.header.Statistics.MaxValue
}
func (v1 DataPageHeaderV1) String() string {
return fmt.Sprintf("DATA_PAGE_HEADER{NumValues=%d,Encoding=%s}",
v1.header.NumValues,
v1.header.Encoding)
}
// DataPageHeaderV2 is an implementation of the DataPageHeader interface
// representing data pages version 2.
type DataPageHeaderV2 struct {
header *format.DataPageHeaderV2
}
func (v2 DataPageHeaderV2) NumValues() int64 {
return int64(v2.header.NumValues)
}
func (v2 DataPageHeaderV2) NumNulls() int64 {
return int64(v2.header.NumNulls)
}
func (v2 DataPageHeaderV2) NumRows() int64 {
return int64(v2.header.NumRows)
}
func (v2 DataPageHeaderV2) RepetitionLevelsByteLength() int64 {
return int64(v2.header.RepetitionLevelsByteLength)
}
func (v2 DataPageHeaderV2) DefinitionLevelsByteLength() int64 {
return int64(v2.header.DefinitionLevelsByteLength)
}
func (v2 DataPageHeaderV2) RepetitionLevelEncoding() format.Encoding {
return format.RLE
}
func (v2 DataPageHeaderV2) DefinitionLevelEncoding() format.Encoding {
return format.RLE
}
func (v2 DataPageHeaderV2) Encoding() format.Encoding {
return v2.header.Encoding
}
func (v2 DataPageHeaderV2) PageType() format.PageType {
return format.DataPageV2
}
func (v2 DataPageHeaderV2) NullCount() int64 {
return v2.header.Statistics.NullCount
}
func (v2 DataPageHeaderV2) MinValue() []byte {
return v2.header.Statistics.MinValue
}
func (v2 DataPageHeaderV2) MaxValue() []byte {
return v2.header.Statistics.MaxValue
}
func (v2 DataPageHeaderV2) IsCompressed() bool {
return v2.header.IsCompressed == nil || *v2.header.IsCompressed
}
func (v2 DataPageHeaderV2) String() string {
return fmt.Sprintf("DATA_PAGE_HEADER_V2{NumValues=%d,NumNulls=%d,NumRows=%d,Encoding=%s,IsCompressed=%t}",
v2.header.NumValues,
v2.header.NumNulls,
v2.header.NumRows,
v2.header.Encoding,
v2.IsCompressed())
}
type unknownPageHeader struct {
header *format.PageHeader
}
func (u unknownPageHeader) NumValues() int64 {
return 0
}
func (u unknownPageHeader) Encoding() format.Encoding {
return -1
}
func (u unknownPageHeader) PageType() format.PageType {
return u.header.Type
}
func (u unknownPageHeader) String() string {
return fmt.Sprintf("UNKNOWN_PAGE_HEADER{Type=%d}", u.header.Type)
}
var (
_ PageHeader = DictionaryPageHeader{}
_ DataPageHeader = DataPageHeaderV1{}
_ DataPageHeader = DataPageHeaderV2{}
_ PageHeader = unknownPageHeader{}
)