forked from parquet-go/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolumn_buffer_uint64_test.go
More file actions
199 lines (171 loc) · 4.74 KB
/
Copy pathcolumn_buffer_uint64_test.go
File metadata and controls
199 lines (171 loc) · 4.74 KB
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
package parquet
import (
"math"
"testing"
)
// TestUint64ColumnBufferWriteTypes tests that uint64ColumnBuffer
// correctly converts various types to uint64
func TestColumnBufferUint64WriteTypes(t *testing.T) {
tests := []struct {
name string
writeOp func(*uint64ColumnBuffer)
expected uint64
}{
{
name: "writeBoolean_false",
writeOp: func(col *uint64ColumnBuffer) {
col.writeBoolean(columnLevels{}, false)
},
expected: 0,
},
{
name: "writeBoolean_true",
writeOp: func(col *uint64ColumnBuffer) {
col.writeBoolean(columnLevels{}, true)
},
expected: 1,
},
{
name: "writeInt32_positive",
writeOp: func(col *uint64ColumnBuffer) {
col.writeInt32(columnLevels{}, 42)
},
expected: 42,
},
{
name: "writeInt64_positive",
writeOp: func(col *uint64ColumnBuffer) {
col.writeInt64(columnLevels{}, 123456789012345)
},
expected: 123456789012345,
},
{
name: "writeFloat_positive",
writeOp: func(col *uint64ColumnBuffer) {
col.writeFloat(columnLevels{}, 3.14)
},
expected: 3,
},
{
name: "writeDouble_positive",
writeOp: func(col *uint64ColumnBuffer) {
col.writeDouble(columnLevels{}, 42.7)
},
expected: 42,
},
{
name: "writeByteArray_valid",
writeOp: func(col *uint64ColumnBuffer) {
col.writeByteArray(columnLevels{}, []byte("123456789"))
},
expected: 123456789,
},
{
name: "writeNull",
writeOp: func(col *uint64ColumnBuffer) {
col.writeNull(columnLevels{})
},
expected: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
tt.writeOp(col)
if col.Len() != 1 {
t.Fatalf("expected 1 value, got %d", col.Len())
}
values := make([]Value, 1)
n, err := col.ReadValuesAt(values, 0)
if err != nil || n != 1 {
t.Fatalf("failed to read value: %v", err)
}
actual := values[0].Uint64()
if actual != tt.expected {
t.Errorf("expected %v, got %v", tt.expected, actual)
}
})
}
}
// TestUint64ColumnBufferWriteInt96 tests writeInt96 conversion
func TestColumnBufferUint64WriteInt96(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeInt96(columnLevels{}, [3]uint32{42, 0, 0})
values := make([]Value, 1)
col.ReadValuesAt(values, 0)
actual := values[0].Uint64()
if actual != 42 {
t.Errorf("expected 42, got %v", actual)
}
}
// TestUint64ColumnBufferWrapping documents wrapping behavior for negative values
func TestColumnBufferUint64Wrapping(t *testing.T) {
t.Run("negative_int32_wraps", func(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeInt32(columnLevels{}, -1)
values := make([]Value, 1)
col.ReadValuesAt(values, 0)
actual := values[0].Uint64()
if actual != math.MaxUint64 {
t.Errorf("expected MaxUint64, got %d", actual)
}
})
t.Run("negative_int64_wraps", func(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeInt64(columnLevels{}, -1)
values := make([]Value, 1)
col.ReadValuesAt(values, 0)
actual := values[0].Uint64()
if actual != math.MaxUint64 {
t.Errorf("expected MaxUint64, got %d", actual)
}
})
t.Run("negative_float_wraps", func(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeFloat(columnLevels{}, -1.0)
values := make([]Value, 1)
col.ReadValuesAt(values, 0)
values[0].Uint64()
})
t.Run("negative_double_wraps", func(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeDouble(columnLevels{}, -1.0)
values := make([]Value, 1)
col.ReadValuesAt(values, 0)
values[0].Uint64()
})
}
// TestUint64ColumnBufferWriteByteArrayInvalid tests that invalid strings default to 0
func TestColumnBufferUint64WriteByteArrayInvalid(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic for invalid byte array")
}
}()
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeByteArray(columnLevels{}, []byte("not a number"))
}
// TestUint64ColumnBufferWriteMultipleValues tests writing multiple values
func TestColumnBufferUint64WriteMultipleValues(t *testing.T) {
col := newUint64ColumnBuffer(Uint(64).Type(), 0, 10)
col.writeInt32(columnLevels{}, 1)
col.writeInt64(columnLevels{}, 2)
col.writeFloat(columnLevels{}, 3.9)
col.writeBoolean(columnLevels{}, true)
col.writeNull(columnLevels{})
if col.Len() != 5 {
t.Fatalf("expected 5 values, got %d", col.Len())
}
expected := []uint64{1, 2, 3, 1, 0}
values := make([]Value, 5)
n, err := col.ReadValuesAt(values, 0)
if err != nil || n != 5 {
t.Fatalf("failed to read values: %v", err)
}
for i, exp := range expected {
actual := values[i].Uint64()
if actual != exp {
t.Errorf("index %d: expected %d, got %d", i, exp, actual)
}
}
}