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