github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/null_test.go (about) 1 //go:build go1.18 2 3 package parquet 4 5 import ( 6 "reflect" 7 "testing" 8 9 "github.com/segmentio/parquet-go/deprecated" 10 "github.com/segmentio/parquet-go/internal/quick" 11 ) 12 13 func TestNullIndex(t *testing.T) { 14 testNullIndex[bool](t) 15 testNullIndex[int](t) 16 testNullIndex[int32](t) 17 testNullIndex[int64](t) 18 testNullIndex[uint](t) 19 testNullIndex[uint32](t) 20 testNullIndex[uint64](t) 21 testNullIndex[float32](t) 22 testNullIndex[float64](t) 23 testNullIndex[[10]byte](t) 24 testNullIndex[[16]byte](t) 25 testNullIndex[deprecated.Int96](t) 26 testNullIndex[string](t) 27 testNullIndex[*struct{}](t) 28 } 29 30 func testNullIndex[T comparable](t *testing.T) { 31 var zero T 32 t.Helper() 33 t.Run(reflect.TypeOf(zero).String(), func(t *testing.T) { 34 err := quick.Check(func(data []T) bool { 35 if len(data) == 0 { 36 return true 37 } 38 39 want := make([]uint64, (len(data)+63)/64) 40 got := make([]uint64, (len(data)+63)/64) 41 42 for i := range data { 43 if (i % 2) == 0 { 44 data[i] = zero 45 } 46 } 47 48 array := makeArrayOf(data) 49 nullIndex[T](want, array) 50 nullIndexFuncOf(reflect.TypeOf(zero))(got, array) 51 52 if !reflect.DeepEqual(want, got) { 53 t.Errorf("unexpected null index\nwant = %064b\ngot = %064b", want, got) 54 return false 55 } 56 return true 57 }) 58 if err != nil { 59 t.Error(err) 60 } 61 }) 62 } 63 64 func BenchmarkNullIndex(b *testing.B) { 65 benchmarkNullIndex[bool](b) 66 benchmarkNullIndex[int](b) 67 benchmarkNullIndex[int32](b) 68 benchmarkNullIndex[int64](b) 69 benchmarkNullIndex[uint](b) 70 benchmarkNullIndex[uint32](b) 71 benchmarkNullIndex[uint64](b) 72 benchmarkNullIndex[float32](b) 73 benchmarkNullIndex[float64](b) 74 benchmarkNullIndex[[10]byte](b) 75 benchmarkNullIndex[[16]byte](b) 76 benchmarkNullIndex[deprecated.Int96](b) 77 benchmarkNullIndex[string](b) 78 benchmarkNullIndex[[]struct{}](b) 79 benchmarkNullIndex[*struct{}](b) 80 } 81 82 func benchmarkNullIndex[T any](b *testing.B) { 83 const N = 1000 84 85 var zero T 86 typ := reflect.TypeOf(zero) 87 null := nullIndexFuncOf(typ) 88 data := makeArrayOf(make([]T, N)) 89 bits := make([]uint64, (N+63)/64) 90 91 b.Run(typ.String(), func(b *testing.B) { 92 for i := 0; i < b.N; i++ { 93 null(bits, data) 94 } 95 b.SetBytes(int64(typ.Size() * N)) 96 }) 97 }