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 4f5b7f856 fix(compaction): match float partitions across a float to
double promotion (#2653)
4f5b7f856 is described below
commit 4f5b7f8562347e88d702aa661ba19f8c96a13308
Author: Neelesh Salian <[email protected]>
AuthorDate: Fri Nov 20 12:32:08 2026 -0800
fix(compaction): match float partitions across a float to double promotion
(#2653)
---
table/compaction/eq_delete_decision.go | 22 +++++++++++
table/compaction/eq_delete_decision_test.go | 30 +++++++++++++++
table/compaction/partition_tuple_test.go | 1 +
table/partition_promotion_deletes_test.go | 57 ++++++++++++++++++++++++-----
4 files changed, 101 insertions(+), 9 deletions(-)
diff --git a/table/compaction/eq_delete_decision.go
b/table/compaction/eq_delete_decision.go
index 34de3c5b0..5c579c480 100644
--- a/table/compaction/eq_delete_decision.go
+++ b/table/compaction/eq_delete_decision.go
@@ -19,6 +19,7 @@ package compaction
import (
"fmt"
+ "maps"
"math"
"slices"
"strconv"
@@ -96,6 +97,9 @@ func (s *SurvivorSurvey) AddSurvivorWithSpec(specID int32,
partition map[int]any
} else {
tuple := appendPartitionTuple(nil, partition)
updatePartitionMinSeq(s.PartMinSeq, string(tuple), seq)
+ if widened, ok := widenFloat32PartitionValues(partition); ok {
+ tuple = appendPartitionTuple(tuple[:0], widened)
+ }
specKey = partitionBucketKeyFromTuple(specID, tuple)
}
@@ -121,6 +125,9 @@ func (s *SurvivorSurvey) specAwareApplicableMinSeq(
if isUnpartitioned {
return s.minSeq
}
+ if widened, ok := widenFloat32PartitionValues(eqPartition); ok {
+ eqPartition = widened
+ }
if v, ok := s.specPartMinSeq[partitionBucketKey(eqSpecID,
eqPartition)]; ok {
return v
}
@@ -295,6 +302,21 @@ func appendPartitionTuple(dst []byte, part map[int]any)
[]byte {
return dst
}
+// widenFloat32PartitionValues widens float32 values so pre-promotion
partitions key like later ones.
+func widenFloat32PartitionValues(part map[int]any) (map[int]any, bool) {
+ var widened map[int]any
+ for id, value := range part {
+ if f, ok := value.(float32); ok {
+ if widened == nil {
+ widened = maps.Clone(part)
+ }
+ widened[id] = float64(f)
+ }
+ }
+
+ return widened, widened != nil
+}
+
func updatePartitionMinSeq(partitions map[string]int64, key string, seq int64)
{
if cur, ok := partitions[key]; ok {
seq = min(seq, cur)
diff --git a/table/compaction/eq_delete_decision_test.go
b/table/compaction/eq_delete_decision_test.go
index 94d78a82c..f9ac6ed7a 100644
--- a/table/compaction/eq_delete_decision_test.go
+++ b/table/compaction/eq_delete_decision_test.go
@@ -62,6 +62,36 @@ func TestDecideDeadEqualityDeletesWithSpecs_Predicate(t
*testing.T) {
eqSeq: 5,
expectsDead: false,
},
+ {
+ name: "float partition promoted to double, surviving D
written before ⇒ alive",
+ survivors: []survivor{
+ {specID: 1, partition: map[int]any{1000:
float32(1.1)}, seq: 3},
+ },
+ eqSpecID: 1,
+ eqPart: map[int]any{1000: float64(float32(1.1))},
+ eqSeq: 5,
+ expectsDead: false,
+ },
+ {
+ name: "float partition promoted to double, different
value ⇒ dead",
+ survivors: []survivor{
+ {specID: 1, partition: map[int]any{1000:
float32(1.1)}, seq: 3},
+ },
+ eqSpecID: 1,
+ eqPart: map[int]any{1000: 1.1},
+ eqSeq: 5,
+ expectsDead: true,
+ },
+ {
+ name: "float partition never promoted, surviving D
written before ⇒ alive",
+ survivors: []survivor{
+ {specID: 1, partition: map[int]any{1000:
float32(1.1)}, seq: 3},
+ },
+ eqSpecID: 1,
+ eqPart: map[int]any{1000: float32(1.1)},
+ eqSeq: 5,
+ expectsDead: false,
+ },
{
name: "partition match, surviving D has higher seq ⇒
dead",
survivors: []survivor{
diff --git a/table/compaction/partition_tuple_test.go
b/table/compaction/partition_tuple_test.go
index ca2cffddc..8cacc4574 100644
--- a/table/compaction/partition_tuple_test.go
+++ b/table/compaction/partition_tuple_test.go
@@ -50,6 +50,7 @@ func TestAppendPartitionTupleMatchesFmt(t *testing.T) {
math.Inf(1),
math.Copysign(0, -1),
float32(3.5),
+ float32(1.1),
[]byte{0, 255},
[]int{1, 2},
partitionTupleStringer("x"),
diff --git a/table/partition_promotion_deletes_test.go
b/table/partition_promotion_deletes_test.go
index 16d4fa54a..7054dea65 100644
--- a/table/partition_promotion_deletes_test.go
+++ b/table/partition_promotion_deletes_test.go
@@ -117,19 +117,58 @@ func
TestEqualityDeletesAfterFloatPartitionSourcePromotion(t *testing.T) {
tbl = appendRows(t, tbl, `[{"id": 1, "p": 1.5}, {"id":
2, "p": 1.5}, {"id": 3, "p": 4.5}]`)
tbl = promotePartitionSource(t, tbl,
iceberg.PrimitiveTypes.Float64)
- arrowSc, err := table.SchemaToArrowSchema(tbl.Schema(),
nil, true, false)
- require.NoError(t, err)
// id 3 lives in partition 4.5, so the delete in
partition 4.6
// must not remove it.
- records, release := makeEqDeleteRecords(t, arrowSc,
`[{"id": 1, "p": 1.5}, {"id": 3, "p": 4.6}]`)
- defer release()
-
- tx := tbl.NewTransaction()
- require.NoError(t,
tx.CommitEqualityDeletes(t.Context(), []int{1}, records, nil))
- tbl, err = tx.Commit(t.Context())
- require.NoError(t, err)
+ tbl = commitPartitionedEqualityDeletes(t, tbl, `[{"id":
1, "p": 1.5}, {"id": 3, "p": 4.6}]`)
assert.Equal(t, []int64{2, 3}, idsInTable(t, tbl))
})
}
}
+
+// TestCompactionKeepsEqualityDeleteAfterFloatPartitionSourcePromotion keeps a
delete that still applies to a pre-promotion file.
+func TestCompactionKeepsEqualityDeleteAfterFloatPartitionSourcePromotion(t
*testing.T) {
+ for _, formatVersion := range []string{"2", "3"} {
+ t.Run("v"+formatVersion, func(t *testing.T) {
+ tbl := newPromotablePartitionTable(t, formatVersion,
iceberg.PrimitiveTypes.Float32)
+ tbl = appendRows(t, tbl, `[{"id": 1, "p": 1.1}, {"id":
2, "p": 1.1}]`)
+ tbl = promotePartitionSource(t, tbl,
iceberg.PrimitiveTypes.Float64)
+ tbl = appendRows(t, tbl, `[{"id": 3, "p": 4.5}]`)
+ tbl = appendRows(t, tbl, `[{"id": 4, "p": 4.5}]`)
+
+ tbl = commitPartitionedEqualityDeletes(t, tbl, `[{"id":
1, "p": 1.100000023841858}]`)
+ require.Equal(t, []int64{2, 3, 4}, idsInTable(t, tbl))
+
+ tasks, err := tbl.Scan().PlanFiles(t.Context())
+ require.NoError(t, err)
+ var group table.CompactionTaskGroup
+ for _, task := range tasks {
+ if p, ok :=
task.File.Partition()[1000].(float64); ok && p == 4.5 {
+ group.Tasks = append(group.Tasks, task)
+ group.TotalSizeBytes +=
task.File.FileSizeBytes()
+ }
+ }
+ require.Len(t, group.Tasks, 2)
+
+ _, tbl = runRewriteWithCleanup(t, tbl,
[]table.CompactionTaskGroup{group}, false)
+ assert.Equal(t, []int64{2, 3, 4}, idsInTable(t, tbl))
+ })
+ }
+}
+
+// commitPartitionedEqualityDeletes commits equality deletes on id, with each
row's partition taken from its p value.
+func commitPartitionedEqualityDeletes(t *testing.T, tbl *table.Table,
recordsJSON string) *table.Table {
+ t.Helper()
+
+ arrowSc, err := table.SchemaToArrowSchema(tbl.Schema(), nil, true,
false)
+ require.NoError(t, err)
+ records, release := makeEqDeleteRecords(t, arrowSc, recordsJSON)
+ defer release()
+
+ tx := tbl.NewTransaction()
+ require.NoError(t, tx.CommitEqualityDeletes(t.Context(), []int{1},
records, nil))
+ out, err := tx.Commit(t.Context())
+ require.NoError(t, err)
+
+ return out
+}