-
Notifications
You must be signed in to change notification settings - Fork 53
/
type_int64.go
162 lines (130 loc) · 3.02 KB
/
type_int64.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
package goparquet
import (
"encoding/binary"
"fmt"
"io"
"github.com/fraugster/parquet-go/parquet"
)
type int64PlainDecoder struct {
r io.Reader
}
func (i *int64PlainDecoder) init(r io.Reader) error {
i.r = r
return nil
}
func (i *int64PlainDecoder) decodeValues(dst []interface{}) (int, error) {
var d int64
for idx := range dst {
if err := binary.Read(i.r, binary.LittleEndian, &d); err != nil {
return idx, err
}
dst[idx] = d
}
return len(dst), nil
}
type int64PlainEncoder struct {
w io.Writer
}
func (i *int64PlainEncoder) Close() error {
return nil
}
func (i *int64PlainEncoder) init(w io.Writer) error {
i.w = w
return nil
}
func (i *int64PlainEncoder) encodeValues(values []interface{}) error {
d := make([]int64, len(values))
for i := range values {
d[i] = values[i].(int64)
}
return binary.Write(i.w, binary.LittleEndian, d)
}
type int64DeltaBPDecoder struct {
deltaBitPackDecoder64
}
func (d *int64DeltaBPDecoder) decodeValues(dst []interface{}) (int, error) {
for i := range dst {
u, err := d.next()
if err != nil {
return i, err
}
dst[i] = u
}
return len(dst), nil
}
type int64DeltaBPEncoder struct {
deltaBitPackEncoder64
}
func (d *int64DeltaBPEncoder) encodeValues(values []interface{}) error {
for i := range values {
if err := d.addInt64(values[i].(int64)); err != nil {
return err
}
}
return nil
}
type int64Store struct {
repTyp parquet.FieldRepetitionType
stats *int64Stats
pageStats *int64Stats
*ColumnParameters
}
func (is *int64Store) getStats() minMaxValues {
return is.stats
}
func (is *int64Store) getPageStats() minMaxValues {
return is.pageStats
}
func (is *int64Store) params() *ColumnParameters {
if is.ColumnParameters == nil {
panic("ColumnParameters is nil")
}
return is.ColumnParameters
}
func (*int64Store) sizeOf(v interface{}) int {
if vv, ok := v.([]int64); ok {
return 8 * len(vv)
}
return 8
}
func (is *int64Store) parquetType() parquet.Type {
return parquet.Type_INT64
}
func (is *int64Store) repetitionType() parquet.FieldRepetitionType {
return is.repTyp
}
func (is *int64Store) reset(rep parquet.FieldRepetitionType) {
is.repTyp = rep
is.stats.reset()
is.pageStats.reset()
}
func (is *int64Store) setMinMax(j int64) {
is.stats.setMinMax(j)
is.pageStats.setMinMax(j)
}
func (is *int64Store) getValues(v interface{}) ([]interface{}, error) {
var vals []interface{}
switch typed := v.(type) {
case int64:
is.setMinMax(typed)
vals = []interface{}{typed}
case []int64:
if is.repTyp != parquet.FieldRepetitionType_REPEATED {
return nil, fmt.Errorf("the value is not repeated but it is an array")
}
vals = make([]interface{}, len(typed))
for j := range typed {
is.setMinMax(typed[j])
vals[j] = typed[j]
}
default:
return nil, fmt.Errorf("unsupported type for storing in int64 column: %T => %+v", v, v)
}
return vals, nil
}
func (*int64Store) append(arrayIn interface{}, value interface{}) interface{} {
if arrayIn == nil {
arrayIn = make([]int64, 0, 1)
}
return append(arrayIn.([]int64), value.(int64))
}