zeroshade commented on code in PR #1289: URL: https://github.com/apache/arrow-go/pull/1289#discussion_r4530679540
########## parquet/internal/encoding/alp_encoding_benchmark_test.go: ########## @@ -0,0 +1,195 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package encoding_test + +import ( + "fmt" + "math" + "testing" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/parquet" + "github.com/apache/arrow-go/v18/parquet/internal/encoding" +) + +// ALP performance depends on its exception rate. The benchmarks cover no +// exceptions, one exception per ten values, and all exceptions. +var alpBenchmarkCases = []struct { + name string + exceptionInterval int +}{ + {"no exceptions", 0}, + {"10% exceptions", 10}, + {"all exceptions", 1}, +} + +func alpBenchmarkValues[T float32 | float64](size, exceptionInterval int) []T { + values := make([]T, size) + for i := range values { + values[i] = T(i%100000) / 1000 + if exceptionInterval != 0 && i%exceptionInterval == 0 { + values[i] = T(math.Pi) * T(i+1) + } + } + return values +} + +func BenchmarkALPEncodingFloat32(b *testing.B) { + for _, benchmark := range alpBenchmarkCases { + b.Run(benchmark.name, func(b *testing.B) { + for sz := MINSIZE; sz < MAXSIZE+1; sz *= 2 { + b.Run(fmt.Sprintf("len %d", sz), func(b *testing.B) { + values := alpBenchmarkValues[float32](sz, benchmark.exceptionInterval) + encoder := encoding.NewEncoder(parquet.Types.Float, parquet.Encodings.ALP, + false, nil, memory.DefaultAllocator).(encoding.Float32Encoder) + defer encoder.Release() + b.ReportAllocs() + b.ResetTimer() + b.SetBytes(int64(len(values) * arrow.Float32SizeBytes)) + for b.Loop() { + encoder.Put(values) + buf, _ := encoder.FlushValues() + buf.Release() + } Review Comment: No change needed: `testing.B.Loop` was added in Go 1.24, and `go.mod` declares `go 1.26.0`. The benchmarks compile and run. ########## parquet/metadata/column_chunk.go: ########## @@ -405,14 +407,25 @@ func (c *ColumnChunkMetaDataBuilder) Finish(info ChunkMetaInfo, hasDict, dictFal } else { thriftEncodings = append(thriftEncodings, format.Encoding(c.props.DictionaryPageEncoding())) } - } else { // no dictionary + } else if len(encStats.DataEncodingStats) > 0 { + // List what the data pages used rather than what was asked for: a + // writer whose dictionary was dropped before its first page writes + // PLAIN pages whatever encoding the properties name. + for _, e := range slices.Sorted(maps.Keys(encStats.DataEncodingStats)) { Review Comment: No change needed: `slices.Sorted` (with `maps.Keys`) has been in the standard library since Go 1.23, and `go.mod` declares `go 1.26.0`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
