Copilot commented on code in PR #1289: URL: https://github.com/apache/arrow-go/pull/1289#discussion_r4529451805
########## 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: `testing.B` does not have a `Loop()` method in Go versions I’m familiar with, so these benchmarks may not compile depending on the repo’s minimum Go version. To keep benchmarks broadly compatible, use the conventional `for i := 0; i < b.N; i++ { ... }` loop instead. ########## 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: `slices.Sorted` is not a standard-library API (at least up to Go versions I’m aware of), so this likely won’t compile. Consider collecting the keys into a slice, sorting it with `slices.Sort(...)`, then iterating the sorted slice. -- 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]
