forked from segmentio/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
null_test.go
95 lines (83 loc) · 2.08 KB
/
null_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package parquet
import (
"reflect"
"testing"
"github.com/parquet-go/parquet-go/deprecated"
"github.com/parquet-go/parquet-go/internal/quick"
)
func TestNullIndex(t *testing.T) {
testNullIndex[bool](t)
testNullIndex[int](t)
testNullIndex[int32](t)
testNullIndex[int64](t)
testNullIndex[uint](t)
testNullIndex[uint32](t)
testNullIndex[uint64](t)
testNullIndex[float32](t)
testNullIndex[float64](t)
testNullIndex[[10]byte](t)
testNullIndex[[16]byte](t)
testNullIndex[deprecated.Int96](t)
testNullIndex[string](t)
testNullIndex[*struct{}](t)
}
func testNullIndex[T comparable](t *testing.T) {
var zero T
t.Helper()
t.Run(reflect.TypeOf(zero).String(), func(t *testing.T) {
err := quick.Check(func(data []T) bool {
if len(data) == 0 {
return true
}
want := make([]uint64, (len(data)+63)/64)
got := make([]uint64, (len(data)+63)/64)
for i := range data {
if (i % 2) == 0 {
data[i] = zero
}
}
array := makeArrayOf(data)
nullIndex[T](want, array)
nullIndexFuncOf(reflect.TypeOf(zero))(got, array)
if !reflect.DeepEqual(want, got) {
t.Errorf("unexpected null index\nwant = %064b\ngot = %064b", want, got)
return false
}
return true
})
if err != nil {
t.Error(err)
}
})
}
func BenchmarkNullIndex(b *testing.B) {
benchmarkNullIndex[bool](b)
benchmarkNullIndex[int](b)
benchmarkNullIndex[int32](b)
benchmarkNullIndex[int64](b)
benchmarkNullIndex[uint](b)
benchmarkNullIndex[uint32](b)
benchmarkNullIndex[uint64](b)
benchmarkNullIndex[float32](b)
benchmarkNullIndex[float64](b)
benchmarkNullIndex[[10]byte](b)
benchmarkNullIndex[[16]byte](b)
benchmarkNullIndex[deprecated.Int96](b)
benchmarkNullIndex[string](b)
benchmarkNullIndex[[]struct{}](b)
benchmarkNullIndex[*struct{}](b)
}
func benchmarkNullIndex[T any](b *testing.B) {
const N = 1000
var zero T
typ := reflect.TypeOf(zero)
null := nullIndexFuncOf(typ)
data := makeArrayOf(make([]T, N))
bits := make([]uint64, (N+63)/64)
b.Run(typ.String(), func(b *testing.B) {
for i := 0; i < b.N; i++ {
null(bits, data)
}
b.SetBytes(int64(typ.Size() * N))
})
}