This is an automated email from the ASF dual-hosted git repository.

zeroshade 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 31c1c25bf fix(table): keep v2 position deletes when a v3 delete writes 
a file's first DV (#2669)
31c1c25bf is described below

commit 31c1c25bf60041d757ccffd9e360324009868434
Author: Ayaan <[email protected]>
AuthorDate: Mon Nov 23 23:02:42 2026 +0530

    fix(table): keep v2 position deletes when a v3 delete writes a file's first 
DV (#2669)
    
    * fix(table): keep v2 position deletes when a v3 delete writes a file's 
first DV
    
    When a v3 merge-on-read Delete gives a data file its first deletion vector,
    merge the positions from that file's v2 position delete files into the DV
    and remove the file-scoped ones in the same snapshot, as Java's
    BaseDVFileWriter does. Partition-scoped files are kept.
    
    Fixes #2604
    
    Signed-off-by: Ayaan <[email protected]>
    
    * fix(table): load only folded v2 position deletes and document non-replay
    
    Pass the partial files' paths to readDeletesForPaths so a partition-wide v2
    delete file no longer loads every target into memory. Add a test that fails
    without foldPositionDeletes skipping files that already have a DV, and note 
in
    the Delete docs and the unreleased compatibility notes that dropping v2
    position delete files makes the commit non-replayable.
    
    Signed-off-by: Ayaan <[email protected]>
    
    ---------
    
    Signed-off-by: Ayaan <[email protected]>
---
 table/mor_delete_pruning_test.go     |   8 +-
 table/mor_v3_upgrade_deletes_test.go | 224 +++++++++++++++++++++++++++++++++++
 table/table.go                       |   6 +-
 table/transaction_delete.go          | 117 ++++++++++++++++--
 website/src/releases.md              |   1 +
 5 files changed, 342 insertions(+), 14 deletions(-)

diff --git a/table/mor_delete_pruning_test.go b/table/mor_delete_pruning_test.go
index 3b919d380..93f80fd69 100644
--- a/table/mor_delete_pruning_test.go
+++ b/table/mor_delete_pruning_test.go
@@ -236,6 +236,12 @@ func 
TestV3MergeOnReadDoubleDeletePartitionedMergesDeletionVectors(t *testing.T)
 func newPartitionedMergeOnReadTestTable(t *testing.T) *table.Table {
        t.Helper()
 
+       return newPartitionedMergeOnReadTestTableVersion(t, "3")
+}
+
+func newPartitionedMergeOnReadTestTableVersion(t *testing.T, formatVersion 
string) *table.Table {
+       t.Helper()
+
        location := filepath.ToSlash(t.TempDir())
        schema := iceberg.NewSchema(0,
                iceberg.NestedField{ID: 1, Name: "id", Type: 
iceberg.PrimitiveTypes.Int64, Required: true},
@@ -249,7 +255,7 @@ func newPartitionedMergeOnReadTestTable(t *testing.T) 
*table.Table {
        })
        meta, err := table.NewMetadata(schema, &spec, table.UnsortedSortOrder, 
location,
                iceberg.Properties{
-                       table.PropertyFormatVersion: "3",
+                       table.PropertyFormatVersion: formatVersion,
                        table.WriteDeleteModeKey:    table.WriteModeMergeOnRead,
                })
        require.NoError(t, err)
diff --git a/table/mor_v3_upgrade_deletes_test.go 
b/table/mor_v3_upgrade_deletes_test.go
new file mode 100644
index 000000000..630cd3f0c
--- /dev/null
+++ b/table/mor_v3_upgrade_deletes_test.go
@@ -0,0 +1,224 @@
+// 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_test
+
+import (
+       "testing"
+
+       "github.com/apache/iceberg-go"
+       "github.com/apache/iceberg-go/table"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+const abcde = 
`[{"id":1,"data":"a"},{"id":2,"data":"b"},{"id":3,"data":"c"},{"id":4,"data":"d"},{"id":5,"data":"e"}]`
+
+func deleteID(t *testing.T, tbl *table.Table, id int64) *table.Table {
+       t.Helper()
+
+       tbl, err := tbl.Delete(t.Context(), 
iceberg.EqualTo(iceberg.Reference("id"), id), nil)
+       require.NoError(t, err)
+
+       return tbl
+}
+
+func upgradeToV3(t *testing.T, tbl *table.Table) *table.Table {
+       t.Helper()
+
+       tx := tbl.NewTransaction()
+       require.NoError(t, tx.UpgradeFormatVersion(3))
+       tbl, err := tx.Commit(t.Context())
+       require.NoError(t, err)
+
+       return tbl
+}
+
+func livePositionDeleteFiles(t *testing.T, tbl *table.Table) int {
+       t.Helper()
+
+       return liveDeleteFileCount(t, tbl, iceberg.EntryContentPosDeletes)
+}
+
+// The first v3 delete on a file must carry over the v2 position deletes, or 
readers
+// (which ignore position deletes once a file has a DV) bring those rows back. 
See #2604.
+func TestV3MergeOnReadUpgradeKeepsPositionDeletes(t *testing.T) {
+       tbl := appendRows(t, newMergeOnReadTestTableVersion(t, "2"), abcde)
+       tbl = deleteID(t, tbl, 1)
+       tbl = upgradeToV3(t, tbl)
+       require.Equal(t, []int64{2, 3, 4, 5}, idsInTable(t, tbl))
+
+       tbl = deleteID(t, tbl, 2)
+       assert.Equal(t, []int64{3, 4, 5}, idsInTable(t, tbl), "the pre-upgrade 
delete of id=1 must survive")
+       assert.Equal(t, 1, liveDVCount(t, tbl))
+       assert.Zero(t, livePositionDeleteFiles(t, tbl), "the folded position 
delete file must be dropped")
+
+       tbl = deleteID(t, tbl, 3)
+       assert.Equal(t, []int64{4, 5}, idsInTable(t, tbl))
+       assert.Equal(t, 1, liveDVCount(t, tbl))
+}
+
+func TestV3MergeOnReadUpgradeKeepsMultiplePositionDeleteFiles(t *testing.T) {
+       tbl := appendRows(t, newMergeOnReadTestTableVersion(t, "2"), abcde)
+       tbl = deleteID(t, tbl, 1)
+       tbl = deleteID(t, tbl, 2)
+       require.Equal(t, 2, livePositionDeleteFiles(t, tbl))
+       tbl = upgradeToV3(t, tbl)
+
+       tbl = deleteID(t, tbl, 3)
+       assert.Equal(t, []int64{4, 5}, idsInTable(t, tbl))
+       assert.Equal(t, 1, liveDVCount(t, tbl))
+       assert.Zero(t, livePositionDeleteFiles(t, tbl))
+}
+
+// One partition-scoped position delete file covers two data files. Like Java, 
it stays in the table
+// (readers ignore it for a file with a DV and still apply it to the other), 
but its positions
+// are folded into each file's first DV.
+func TestV3MergeOnReadUpgradeKeepsSharedPositionDeleteFile(t *testing.T) {
+       tbl := newMergeOnReadTestTableVersion(t, "2")
+       tbl = appendRows(t, tbl, `[{"id":1,"data":"a"},{"id":2,"data":"b"}]`)
+       tbl = appendRows(t, tbl, `[{"id":3,"data":"c"},{"id":4,"data":"d"}]`)
+
+       tbl, err := tbl.Delete(t.Context(), 
iceberg.IsIn(iceberg.Reference("id"), int64(1), int64(3)), nil)
+       require.NoError(t, err)
+       require.Equal(t, 1, livePositionDeleteFiles(t, tbl), "one delete file 
must cover both data files")
+       tbl = upgradeToV3(t, tbl)
+
+       tbl = deleteID(t, tbl, 2)
+       assert.Equal(t, []int64{4}, idsInTable(t, tbl))
+       assert.Equal(t, 1, livePositionDeleteFiles(t, tbl), "the second file 
still needs the shared delete file")
+
+       tbl = deleteID(t, tbl, 4)
+       assert.Empty(t, idsInTable(t, tbl))
+       assert.Equal(t, 2, liveDVCount(t, tbl))
+       assert.Equal(t, 1, livePositionDeleteFiles(t, tbl), "a shared delete 
file is not dropped")
+}
+
+// A file that already has a DV must not be seeded again from a shared v2 
delete file that still
+// covers it: the seed would replace the DV's bitmap and bring back the row an 
earlier v3 delete removed.
+func TestV3MergeOnReadSharedPositionDeleteFileDoesNotResurrectDVRows(t 
*testing.T) {
+       tbl := newMergeOnReadTestTableVersion(t, "2")
+       tbl = appendRows(t, tbl, 
`[{"id":1,"data":"a"},{"id":2,"data":"b"},{"id":3,"data":"c"}]`)
+       tbl = appendRows(t, tbl, `[{"id":4,"data":"d"},{"id":5,"data":"e"}]`)
+
+       tbl, err := tbl.Delete(t.Context(), 
iceberg.IsIn(iceberg.Reference("id"), int64(1), int64(4)), nil)
+       require.NoError(t, err)
+       require.Equal(t, 1, livePositionDeleteFiles(t, tbl), "one delete file 
must cover both data files")
+       tbl = upgradeToV3(t, tbl)
+
+       tbl = deleteID(t, tbl, 2)
+       require.Equal(t, []int64{3, 5}, idsInTable(t, tbl))
+       require.Equal(t, 1, livePositionDeleteFiles(t, tbl), "the shared delete 
file still covers the second file")
+
+       tbl = deleteID(t, tbl, 3)
+       assert.Equal(t, []int64{5}, idsInTable(t, tbl), "id=2 was deleted by 
the first DV and must stay deleted")
+}
+
+func TestV3MergeOnReadUpgradeKeepsPartitionedPositionDeletes(t *testing.T) {
+       tbl := newPartitionedMergeOnReadTestTableVersion(t, "2")
+       tbl = appendRows(t, tbl, 
`[{"id":1,"category":"x"},{"id":2,"category":"x"},{"id":3,"category":"x"},`+
+               
`{"id":4,"category":"y"},{"id":5,"category":"y"},{"id":6,"category":"y"}]`)
+       tbl = deleteID(t, tbl, 1)
+       tbl = deleteID(t, tbl, 4)
+       tbl = upgradeToV3(t, tbl)
+
+       tbl = deleteID(t, tbl, 2)
+       tbl = deleteID(t, tbl, 5)
+       assert.Equal(t, []int64{3, 6}, idsInTable(t, tbl))
+       assert.Equal(t, 2, liveDVCount(t, tbl))
+       assert.Zero(t, livePositionDeleteFiles(t, tbl))
+}
+
+func TestV3MergeOnReadUpgradeKeepsEqualityDeletes(t *testing.T) {
+       tbl := appendRows(t, newMergeOnReadTestTableVersion(t, "2"), abcde)
+       tbl = appendEqualityDelete(t, tbl, []int{1}, `[{"id":1}]`)
+       tbl = deleteID(t, tbl, 2)
+       tbl = upgradeToV3(t, tbl)
+
+       tbl = deleteID(t, tbl, 3)
+       assert.Equal(t, []int64{4, 5}, idsInTable(t, tbl))
+       assert.Equal(t, 1, liveDeleteFileCount(t, tbl, 
iceberg.EntryContentEqDeletes))
+       assert.Zero(t, livePositionDeleteFiles(t, tbl))
+}
+
+// Dropping the v2 position delete file cannot be replayed on a changed table: 
a peer commit
+// must fail the staged delete instead of being merged over it.
+func TestV3MergeOnReadUpgradeFoldFailsOnConcurrentCommit(t *testing.T) {
+       tbl := appendRows(t, newMergeOnReadTestTableVersion(t, "2"), abcde)
+       tbl = deleteID(t, tbl, 1)
+       tbl = upgradeToV3(t, tbl)
+
+       tx := tbl.NewTransaction()
+       require.NoError(t, tx.Delete(t.Context(), 
iceberg.EqualTo(iceberg.Reference("id"), int64(2)), nil))
+       peer := appendRows(t, tbl, `[{"id":10,"data":"z"}]`)
+
+       _, err := tx.Commit(t.Context())
+       require.ErrorIs(t, err, table.ErrCommitFailed)
+       assert.Equal(t, []int64{2, 3, 4, 5, 10}, idsInTable(t, peer))
+
+       peer = deleteID(t, peer, 2)
+       assert.Equal(t, []int64{3, 4, 5, 10}, idsInTable(t, peer), "a manual 
retry on the new table succeeds")
+}
+
+// A partition spec change between the v2 delete and the upgrade must not lose 
the old delete.
+func TestV3MergeOnReadUpgradeAfterSpecEvolutionKeepsPositionDeletes(t 
*testing.T) {
+       tests := map[string]struct {
+               tbl  func(*testing.T) *table.Table
+               rows string
+       }{
+               "unpartitioned": {
+                       func(t *testing.T) *table.Table { return 
newMergeOnReadTestTableVersion(t, "2") },
+                       
`[{"id":1,"data":"a"},{"id":2,"data":"b"},{"id":3,"data":"c"}]`,
+               },
+               "partitioned": {
+                       func(t *testing.T) *table.Table { return 
newPartitionedMergeOnReadTestTableVersion(t, "2") },
+                       
`[{"id":1,"category":"x"},{"id":2,"category":"x"},{"id":3,"category":"x"}]`,
+               },
+       }
+       for name, tc := range tests {
+               t.Run(name, func(t *testing.T) {
+                       tbl := deleteID(t, appendRows(t, tc.tbl(t), tc.rows), 1)
+
+                       evolve := tbl.NewTransaction()
+                       require.NoError(t, 
evolve.UpdateSpec(true).AddIdentity("id").Commit())
+                       tbl, err := evolve.Commit(t.Context())
+                       require.NoError(t, err)
+                       tbl = deleteID(t, upgradeToV3(t, tbl), 2)
+
+                       assert.Equal(t, []int64{3}, idsInTable(t, tbl))
+                       assert.Equal(t, 1, liveDVCount(t, tbl))
+                       assert.Zero(t, livePositionDeleteFiles(t, tbl))
+               })
+       }
+}
+
+// A delete whose filter passes file-level metrics but matches no row still 
writes the DV seeded
+// with the v2 positions. The file-scoped position delete file is dropped in 
the same commit, so
+// without that DV its deletes would be lost.
+func TestV3MergeOnReadUpgradeSeedOnlyDeletionVector(t *testing.T) {
+       tbl := appendRows(t, newMergeOnReadTestTableVersion(t, "2"), abcde)
+       tbl = deleteID(t, tbl, 1)
+       tbl = upgradeToV3(t, tbl)
+
+       // "bb" lies between the data column bounds "a" and "e" but is not a 
value.
+       tbl, err := tbl.Delete(t.Context(), 
iceberg.EqualTo(iceberg.Reference("data"), "bb"), nil)
+       require.NoError(t, err)
+
+       assert.Equal(t, []int64{2, 3, 4, 5}, idsInTable(t, tbl))
+       assert.Equal(t, 1, liveDVCount(t, tbl), "the seeded DV must be written 
even with no new positions")
+       assert.Zero(t, livePositionDeleteFiles(t, tbl))
+}
diff --git a/table/table.go b/table/table.go
index 66bbce6d8..e89d24119 100644
--- a/table/table.go
+++ b/table/table.go
@@ -430,8 +430,10 @@ func (t Table) Overwrite(ctx context.Context, rdr 
array.RecordReader, snapshotPr
 // On a v3 table, every data file the delete removes or rewrites takes its 
deletion vector with it.
 // A merge-on-read delete replaces the existing deletion vector of a file it 
deletes rows from.
 //
-// A commit that removes a deletion vector is not replayed: if another writer 
commits first,
-// it fails with ErrCommitFailed instead of refreshing and retrying, so reload 
the table and run the delete again.
+// A commit that removes a deletion vector, or that drops v2 position delete 
files because the first deletion
+// vector of a file replaces them, is not replayed: if another writer commits 
first, it fails with ErrCommitFailed
+// instead of refreshing and retrying. On a table upgraded from v2 the first 
delete after the upgrade can hit
+// this, so reload the table and run the delete again.
 //
 // The concurrency parameter controls the level of parallelism for manifest 
processing and file rewriting and
 // can be overridden using the WithOverwriteConcurrency option. Defaults to 
runtime.GOMAXPROCS(0).
diff --git a/table/transaction_delete.go b/table/transaction_delete.go
index bab0e1a4d..c8c796f6b 100644
--- a/table/transaction_delete.go
+++ b/table/transaction_delete.go
@@ -22,6 +22,7 @@ import (
        "encoding/json"
        "fmt"
        "iter"
+       "maps"
        "runtime"
        "slices"
        "strings"
@@ -167,11 +168,21 @@ func (t *Transaction) performMergeOnReadDeletion(ctx 
context.Context, snapshotPr
        }
 
        // On v3 every removed file takes its deletion vector with it, and a 
partially deleted file's vector is
-       // merged into its replacement. Both need only the deletion vectors, 
read once.
-       // DVs only exist from v3, so v2 skips the read.
-       var dvs liveDeletionVectors
+       // merged into its replacement. A file's first vector also absorbs its 
v2 position deletes, which readers
+       // stop applying once the file has a vector. DVs only exist from v3, so 
v2 skips the read.
+       var (
+               dvs    liveDeletionVectors
+               folded foldedPositionDeletes
+       )
        if meta.formatVersion >= 3 && (len(filesToDelete) > 0 || 
len(withPartialDeletions) > 0) {
-               dvs, err = t.readLiveDeletionVectors(ctx, fs)
+               classified, err := t.classifyLiveDeletes(ctx, fs)
+               if err != nil {
+                       return nil, err
+               }
+               if dvs, err = buildDVIndex(classified.dvEntries); err != nil {
+                       return nil, err
+               }
+               folded, err = foldPositionDeletes(ctx, fs, 
withPartialDeletions, classified.positionalDeleteEntries, dvs)
                if err != nil {
                        return nil, err
                }
@@ -186,7 +197,7 @@ func (t *Transaction) performMergeOnReadDeletion(ctx 
context.Context, snapshotPr
                for _, entry := range withPartialDeletions {
                        partialFiles = append(partialFiles, entry.DataFile())
                }
-               referenced, err := t.writePositionDeletesForFiles(ctx, fs, 
updater, dvs, partialFiles, filter, caseSensitive, concurrency, commitUUID)
+               referenced, err := t.writePositionDeletesForFiles(ctx, fs, 
updater, dvs, folded, partialFiles, filter, caseSensitive, concurrency, 
commitUUID)
                if err != nil {
                        return nil, err
                }
@@ -273,8 +284,10 @@ func WithDeleteCaseInsensitive() DeleteOption {
 // On a v3 table, every data file the delete removes or rewrites takes its 
deletion vector with it.
 // A merge-on-read delete replaces the existing deletion vector of a file it 
deletes rows from.
 //
-// A commit that removes a deletion vector is not replayed: if another writer 
commits first,
-// it fails with ErrCommitFailed instead of refreshing and retrying, so reload 
the table and run the delete again.
+// A commit that removes a deletion vector, or that drops v2 position delete 
files because the first deletion
+// vector of a file replaces them, is not replayed: if another writer commits 
first, it fails with ErrCommitFailed
+// instead of refreshing and retrying. On a table upgraded from v2 the first 
delete after the upgrade can hit
+// this, so reload the table and run the delete again.
 //
 // The concurrency parameter controls the level of parallelism for manifest 
processing and file rewriting and
 // can be overridden using the WithOverwriteConcurrency option. Defaults to 
runtime.GOMAXPROCS(0).
@@ -573,9 +586,10 @@ func (t *Transaction) readPlanningDeletes(ctx 
context.Context, fs io.IO, builtMe
        return planningDeletes{positional: positional, dvs: dvs, equality: 
equality}, nil
 }
 
-// readLiveDeletionVectors returns the live deletion vectors of the planning 
snapshot. Merge-on-read uses it
-// because it only drops or merges deletion vectors, so it skips building the 
position and equality delete
-// indexes and neither pays for them nor fails on them.
+// readLiveDeletionVectors returns the live deletion vectors of the planning 
snapshot. ReplaceDataFiles,
+// ReplaceDataFilesByPath and dynamic partition overwrite use it because they 
only remove deletion vectors
+// together with their data files, so it skips building the position and 
equality delete indexes and neither
+// pays for them nor fails on them.
 func (t *Transaction) readLiveDeletionVectors(ctx context.Context, fs io.IO) 
(liveDeletionVectors, error) {
        classified, err := t.classifyLiveDeletes(ctx, fs)
        if err != nil {
@@ -900,7 +914,7 @@ func isNullPositionDeletePath(values 
arrow.TypedArray[string], column arrow.Arra
 // files that match filter, appends them to updater, and returns the distinct
 // data-file paths those deletes reference, including paths in v2 delete files
 // that cover more than one data file.
-func (t *Transaction) writePositionDeletesForFiles(ctx context.Context, fs 
io.IO, updater *snapshotProducer, dvs liveDeletionVectors, files 
[]iceberg.DataFile, filter iceberg.BooleanExpression, caseSensitive bool, 
concurrency int, commitUUID uuid.UUID) ([]string, error) {
+func (t *Transaction) writePositionDeletesForFiles(ctx context.Context, fs 
io.IO, updater *snapshotProducer, dvs liveDeletionVectors, folded 
foldedPositionDeletes, files []iceberg.DataFile, filter 
iceberg.BooleanExpression, caseSensitive bool, concurrency int, commitUUID 
uuid.UUID) ([]string, error) {
        meta, err := t.txnMeta()
        if err != nil {
                return nil, err
@@ -995,6 +1009,10 @@ func (t *Transaction) writePositionDeletesForFiles(ctx 
context.Context, fs io.IO
                existingDVs[df.FilePath()] = entry.DataFile()
                existingDVBitmaps[df.FilePath()] = bitmap
        }
+       // A file without a DV starts from the positions its v2 position 
deletes removed. maps.Copy overwrites,
+       // so this relies on foldPositionDeletes skipping files that already 
have a DV: their bitmap above is the
+       // live one, and a seed from a shared v2 delete file would bring back 
rows that DV deleted.
+       maps.Copy(existingDVBitmaps, folded.seeds)
 
        posDeleteFiles := positionDeleteRecordsToDataFiles(ctx, meta.loc, meta, 
partitionContextByFilePath, recordWritingArgs{
                sc:          PositionalDeleteArrowSchema,
@@ -1030,10 +1048,87 @@ func (t *Transaction) writePositionDeletesForFiles(ctx 
context.Context, fs io.IO
        for _, dvFile := range existingDVs {
                updater.removeDeletionVector(dvFile)
        }
+       for _, f := range folded.drop {
+               updater.removeDeleteFile(f)
+       }
 
        return referenced, nil
 }
 
+// foldedPositionDeletes is what a v3 delete takes over from v2 position 
delete files.
+type foldedPositionDeletes struct {
+       // seeds maps a data file without a deletion vector to the positions 
its position delete files removed.
+       seeds map[string]*dv.RoaringPositionBitmap
+       // drop lists the file-scoped position delete files whose positions 
moved into a seed.
+       drop []iceberg.DataFile
+}
+
+// foldPositionDeletes collects the v2 position deletes of every file in 
partial that has no deletion vector yet.
+//
+// Like Java's BaseDVFileWriter, only file-scoped delete files (one target 
data file) are dropped. A
+// partition-scoped file can cover other data files, so it stays: readers 
ignore it for files with a vector
+// and still apply it to the rest. Dropping is safe because every seeded file 
gets a vector written.
+func foldPositionDeletes(ctx context.Context, fs io.IO, partial 
[]iceberg.ManifestEntry, positional []iceberg.ManifestEntry, dvs 
liveDeletionVectors) (foldedPositionDeletes, error) {
+       var folded foldedPositionDeletes
+       if len(partial) == 0 || len(positional) == 0 {
+               return folded, nil
+       }
+       idx, err := buildPositionalDeleteIndex(positional)
+       if err != nil {
+               return folded, err
+       }
+
+       // Gather each delete file's targets first, so a large partition-scoped 
file loads only the folded positions.
+       folded.seeds = make(map[string]*dv.RoaringPositionBitmap)
+       targets := make(map[string]map[string]struct{}) // delete file path -> 
target paths
+       matches := make(map[string][]iceberg.DataFile)  // target path -> its 
delete files
+       for _, entry := range partial {
+               path := entry.DataFile().FilePath()
+               if _, ok := dvs[path]; ok {
+                       continue
+               }
+               matched, err := idx.forDataFile(entry)
+               if err != nil {
+                       return folded, err
+               }
+               matches[path] = matched
+               for _, del := range matched {
+                       if targets[del.FilePath()] == nil {
+                               targets[del.FilePath()] = 
make(map[string]struct{})
+                       }
+                       targets[del.FilePath()][path] = struct{}{}
+               }
+       }
+
+       read := make(map[string]map[string]*dv.RoaringPositionBitmap) // delete 
file path -> target path -> positions
+       for _, entry := range partial {
+               path := entry.DataFile().FilePath()
+               for _, del := range matches[path] {
+                       bitmaps, ok := read[del.FilePath()]
+                       if !ok {
+                               var err error
+                               if bitmaps, err = 
readPositionDeleteBitmapsForPaths(ctx, fs, del, targets[del.FilePath()]); err 
!= nil {
+                                       return folded, fmt.Errorf("failed to 
read position deletes from %s: %w", del.FilePath(), err)
+                               }
+                               read[del.FilePath()] = bitmaps
+                       }
+                       bitmap, ok := bitmaps[path]
+                       if !ok {
+                               continue
+                       }
+                       if folded.seeds[path] == nil {
+                               folded.seeds[path] = 
dv.NewRoaringPositionBitmap()
+                       }
+                       folded.seeds[path].Or(bitmap)
+                       if referencedDataFilePath(del) == path {
+                               folded.drop = append(folded.drop, del)
+                       }
+               }
+       }
+
+       return folded, nil
+}
+
 func (t *Transaction) makePositionDeleteRecordsForFilter(ctx context.Context, 
fs io.IO, files []iceberg.DataFile, filter iceberg.BooleanExpression, 
caseSensitive bool, concurrency int) (seq2 iter.Seq2[arrow.RecordBatch, error], 
err error) {
        meta, err := t.txnMeta()
        if err != nil {
diff --git a/website/src/releases.md b/website/src/releases.md
index 19be156bc..898869b6e 100644
--- a/website/src/releases.md
+++ b/website/src/releases.md
@@ -70,6 +70,7 @@ Per-release notes (highlights, breaking changes, 
contributors) are published on
 - **`StructType.Fields()` returns a copy.** Changing the returned slice no 
longer changes the struct, matching `ListType.Fields()` and `MapType.Fields()`. 
Build a new type with `NewStructType` instead. `NumFields()` and `Field(i)` 
read fields without copying, and `NewListType` and `NewMapType` are the 
constructors for the other nested types. The exported fields are unchanged for 
now; they become unexported before v1.0.0 (see 
[#2062](https://github.com/apache/iceberg-go/issues/2062)).
 - **`io.StatIO.Stat` accepts a context.** The method now takes a 
`context.Context` before the path, so custom `StatIO` implementations and 
callers must pass the operation context.
 - **Commits retry conflicts by default.** `commit.retry.num-retries` now 
defaults to `4`, as in Java and PyIceberg, so `Commit` refreshes and replays a 
conflicting commit up to four times before returning `ErrCommitFailed`. Set it 
to `0` to keep failing on the first conflict. `table.CommitNumRetriesDefault` 
changes from `0` to `4`.
+- **The first `Delete` on a v3 table upgraded from v2 can fail with 
`ErrCommitFailed`.** A merge-on-read `Delete` that gives a data file its first 
deletion vector now folds that file's v2 position deletes into the vector, so 
those deletes no longer reappear after the upgrade, and drops the file-scoped 
v2 position delete files in the same commit. Like any commit that removes 
delete files, it is not replayed: if another writer commits first, it returns 
`ErrCommitFailed` instead of refreshi [...]
 - **Schema updates assert the last assigned field ID.** When `UpdateSchema` 
adds a schema, the commit now also requires the table's `last-column-id` to 
match the transaction's base, as Iceberg Java does. A stale writer whose base 
predates another writer's column additions now fails with 
`table.ErrCommitFailed` instead of reusing field IDs. Reload the table and 
reapply the schema change.
 - **Schemas store binary and fixed defaults as hex strings.** `NewSchema`, 
`NewSchemaWithIdentifiers` and `UpdateSchema.AddColumn` (through `Apply()`) 
convert `[]byte`, `BinaryLiteral` and `FixedLiteral` defaults of binary and 
fixed fields, including fields nested in structs, lists and maps, to the 
lowercase hex string iceberg-go writes to metadata JSON, so a field read back 
from a schema holds a `string` such as `"0aff"`. Code that type-asserts these 
defaults to `[]byte` must decode the [...]
 - **Predicates reject NaN literals when bound.** `EqualTo`, `NotEqualTo`, 
`LessThan`, `LessThanEqual`, `GreaterThan`, `GreaterThanEqual`, `IsIn`, `NotIn` 
and `LiteralPredicate`/`SetPredicate` with a NaN float literal now fail in 
`Bind` with `ErrInvalidArgument`, as Java does. That includes the string 
`"NaN"` on a float column and a NaN on a decimal column, which used to bind as 
zero. Scans, `ExpressionEvaluator` and the metrics evaluators all bind first, 
so they return the error too. Use [...]

Reply via email to