You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by at...@apache.org on 2026/08/27 11:29:15 UTC
(iceberg-go) branch main updated: perf(table): skip metrics after partition rejection (#1771)
This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 267f2775d perf(table): skip metrics after partition rejection (#1771)
267f2775d is described below
commit 267f2775d8da1fd955f998b648c7f9b2115228e6
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Thu Aug 27 13:29:10 2026 +0200
perf(table): skip metrics after partition rejection (#1771)
* perf(table): skip metrics after partition rejection
Signed-off-by: Minh Vu <vu...@gmail.com>
* fix(table): cover manifest filter short-circuit
Signed-off-by: Minh Vu <vu...@gmail.com>
---------
Signed-off-by: Minh Vu <vu...@gmail.com>
---
table/scanner.go | 5 +-
table/scanner_bench_test.go | 117 +++++++++++++++++++++++++++++++++++++++++
table/scanner_internal_test.go | 100 +++++++++++++++++++++++++++++++++++
3 files changed, 221 insertions(+), 1 deletion(-)
diff --git a/table/scanner.go b/table/scanner.go
index a66601b4f..ba9b758e7 100644
--- a/table/scanner.go
+++ b/table/scanner.go
@@ -206,13 +206,16 @@ func openManifest(io io.IO, manifest iceberg.ManifestFile,
if err != nil {
return nil, err
}
+ if !p {
+ continue
+ }
m, err := metricsEval(entry.DataFile())
if err != nil {
return nil, err
}
- if p && m {
+ if m {
out = append(out, entry)
}
}
diff --git a/table/scanner_bench_test.go b/table/scanner_bench_test.go
new file mode 100644
index 000000000..9b2d0a980
--- /dev/null
+++ b/table/scanner_bench_test.go
@@ -0,0 +1,117 @@
+// 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 table
+
+import (
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "testing"
+
+ "github.com/apache/iceberg-go"
+ iceio "github.com/apache/iceberg-go/io"
+)
+
+func BenchmarkOpenManifestPartitionRejectsMostEntries(b *testing.B) {
+ const (
+ entryCount = 1_000
+ rejectThrough = 950
+ )
+
+ spec := partitionedSpec()
+ schema := simpleSchema()
+ snapshotID := int64(1)
+ entries := make([]iceberg.ManifestEntry, entryCount)
+ for i := range entries {
+ value := int32(i)
+ builder, err := iceberg.NewDataFileBuilder(
+ spec,
+ iceberg.EntryContentData,
+ fmt.Sprintf("mem://default/table/data/file-%d.parquet", i),
+ iceberg.ParquetFile,
+ map[int]any{1000: value},
+ nil,
+ nil,
+ 1,
+ 100,
+ )
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ bound := make([]byte, 4)
+ binary.LittleEndian.PutUint32(bound, uint32(value))
+ entries[i] = iceberg.NewManifestEntry(
+ iceberg.EntryStatusADDED,
+ &snapshotID,
+ nil,
+ nil,
+ builder.
+ LowerBoundValues(map[int][]byte{1: bound}).
+ UpperBoundValues(map[int][]byte{1: bound}).
+ Build(),
+ )
+ }
+
+ manifestPath := "mem://default/table/metadata/manifest.avro"
+ var manifestBytes bytes.Buffer
+ manifest, err := iceberg.WriteManifest(
+ manifestPath,
+ &manifestBytes,
+ 2,
+ spec,
+ schema,
+ snapshotID,
+ entries,
+ )
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ fs := iceio.NewMemFS()
+ if err := fs.WriteFile(manifestPath, manifestBytes.Bytes()); err != nil {
+ b.Fatal(err)
+ }
+
+ // This simplified filter isolates skipped metrics evaluation; production
+ // scans build the evaluator through buildPartitionEvaluator.
+ partitionFilter := func(df iceberg.DataFile) (bool, error) {
+ return df.Partition()[1000].(int32) >= rejectThrough, nil
+ }
+ metricsEval, err := newInclusiveMetricsEvaluator(
+ schema,
+ iceberg.EqualTo(iceberg.Reference("id"), int32(entryCount-1)),
+ true,
+ false,
+ )
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ b.ReportAllocs()
+ b.ResetTimer()
+ for range b.N {
+ matched, err := openManifest(fs, manifest, partitionFilter, metricsEval)
+ if err != nil {
+ b.Fatal(err)
+ }
+ if len(matched) != 1 {
+ b.Fatalf("openManifest returned %d entries, want 1", len(matched))
+ }
+ }
+}
diff --git a/table/scanner_internal_test.go b/table/scanner_internal_test.go
index c47dd3a94..3a952e6d7 100644
--- a/table/scanner_internal_test.go
+++ b/table/scanner_internal_test.go
@@ -285,6 +285,106 @@ func TestEqualityDeletePartitionKeyDistinguishesSignedZero(t *testing.T) {
assert.NotEqual(t, negative, positive)
}
+func TestOpenManifestShortCircuitsMetricsEvaluation(t *testing.T) {
+ spec := partitionedSpec()
+ schema := simpleSchema()
+ snapshotID := int64(1)
+
+ builder, err := iceberg.NewDataFileBuilder(
+ spec,
+ iceberg.EntryContentData,
+ "mem://default/table/data/file.parquet",
+ iceberg.ParquetFile,
+ map[int]any{1000: int32(7)},
+ nil,
+ nil,
+ 1,
+ 100,
+ )
+ require.NoError(t, err)
+
+ entry := iceberg.NewManifestEntry(
+ iceberg.EntryStatusADDED,
+ &snapshotID,
+ nil,
+ nil,
+ builder.Build(),
+ )
+ manifestPath := "mem://default/table/metadata/manifest.avro"
+ var manifestBytes bytes.Buffer
+ manifest, err := iceberg.WriteManifest(
+ manifestPath,
+ &manifestBytes,
+ 2,
+ spec,
+ schema,
+ snapshotID,
+ []iceberg.ManifestEntry{entry},
+ )
+ require.NoError(t, err)
+
+ fs := iceio.NewMemFS()
+ require.NoError(t, fs.WriteFile(manifestPath, manifestBytes.Bytes()))
+
+ tests := []struct {
+ name string
+ partitionMatches bool
+ metricsMatches bool
+ metricsErr error
+ wantEvaluations []string
+ wantEntries int
+ }{
+ {
+ name: "partition rejection skips metrics",
+ partitionMatches: false,
+ metricsMatches: true,
+ wantEvaluations: []string{"partition"},
+ },
+ {
+ name: "partition rejection skips metrics errors",
+ partitionMatches: false,
+ metricsErr: errors.New("metrics evaluation should be skipped"),
+ wantEvaluations: []string{"partition"},
+ },
+ {
+ name: "partition acceptance evaluates metrics",
+ partitionMatches: true,
+ metricsMatches: true,
+ wantEvaluations: []string{"partition", "metrics"},
+ wantEntries: 1,
+ },
+ {
+ name: "metrics rejection still prunes accepted partition",
+ partitionMatches: true,
+ metricsMatches: false,
+ wantEvaluations: []string{"partition", "metrics"},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ evaluations := make([]string, 0, 2)
+ entries, err := openManifest(
+ fs,
+ manifest,
+ func(iceberg.DataFile) (bool, error) {
+ evaluations = append(evaluations, "partition")
+
+ return tt.partitionMatches, nil
+ },
+ func(iceberg.DataFile) (bool, error) {
+ evaluations = append(evaluations, "metrics")
+
+ return tt.metricsMatches, tt.metricsErr
+ },
+ )
+ require.NoError(t, err)
+ assert.Equal(t, tt.wantEvaluations, evaluations)
+ assert.Len(t, entries, tt.wantEntries)
+ })
+ }
+}
+
func TestMinSequenceNum(t *testing.T) {
tests := []struct {
name string