forked from parquet-go/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
column_buffer_test.go
77 lines (66 loc) · 1.69 KB
/
column_buffer_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
package parquet
import (
"testing"
)
func TestBroadcastValueInt32(t *testing.T) {
buf := make([]int32, 123)
broadcastValueInt32(buf, 0x0A)
for i, v := range buf {
if v != 0x0A0A0A0A {
t.Fatalf("wrong value at index %d: %v", i, v)
}
}
}
func TestBroadcastRangeInt32(t *testing.T) {
buf := make([]int32, 123)
broadcastRangeInt32(buf, 1)
for i, v := range buf {
if v != int32(1+i) {
t.Fatalf("wrong value at index %d: %v", i, v)
}
}
}
func BenchmarkBroadcastValueInt32(b *testing.B) {
buf := make([]int32, 1000)
for i := 0; i < b.N; i++ {
broadcastValueInt32(buf, -1)
}
b.SetBytes(4 * int64(len(buf)))
}
func BenchmarkBroadcastRangeInt32(b *testing.B) {
buf := make([]int32, 1000)
for i := 0; i < b.N; i++ {
broadcastRangeInt32(buf, 0)
}
b.SetBytes(4 * int64(len(buf)))
}
// https://github.com/segmentio/parquet-go/issues/501
func TestIssue501(t *testing.T) {
col := newBooleanColumnBuffer(BooleanType, 0, 2055208)
// write all trues and then flush the buffer
_, err := col.WriteBooleans([]bool{true, true, true, true, true, true, true, true})
if err != nil {
t.Fatal(err)
}
col.Reset()
// write a single false, we are trying to trip a certain line of code in WriteBooleans
_, err = col.WriteBooleans([]bool{false})
if err != nil {
t.Fatal(err)
}
// now write 7 booleans at once, this will cause WriteBooleans to attempt its "alignment" logic
_, err = col.WriteBooleans([]bool{false, false, false, false, false, false, false})
if err != nil {
panic(err)
}
for i := 0; i < 8; i++ {
read := make([]Value, 1)
_, err = col.ReadValuesAt(read, int64(i))
if err != nil {
t.Fatal(err)
}
if read[0].Boolean() {
t.Fatalf("expected false at index %d", i)
}
}
}