You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/07/24 18:07:49 UTC

(iceberg-go) branch main updated: fix(table): make summary equality nil-safe (#1516)

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 cdb2a8b08 fix(table): make summary equality nil-safe (#1516)
cdb2a8b08 is described below

commit cdb2a8b08abefa4cca8276eecf25e3f4277681ec
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Jul 24 20:07:44 2026 +0200

    fix(table): make summary equality nil-safe (#1516)
    
    ## Summary
    
    - handle nil snapshot summaries symmetrically in `Summary.Equals`
    - cover direct summary comparison and `Snapshot.Equals` in both operand
    orders
    
    ## Why
    
    `Summary.Equals` handled a non-nil receiver with a nil argument, but not
    the reverse. Comparing a snapshot without a summary to one with a
    summary dereferenced the nil receiver and panicked. Equality should
    return false regardless of operand order.
    
    ## Testing
    
    - `go test ./...`
    - `go test -race ./table`
    - `golangci-lint run --timeout=10m`
    - `go vet ./...`
---
 table/snapshots.go      |  2 +-
 table/snapshots_test.go | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/table/snapshots.go b/table/snapshots.go
index 073570dc5..2de54b6f6 100644
--- a/table/snapshots.go
+++ b/table/snapshots.go
@@ -199,7 +199,7 @@ func (s *Summary) Equals(other *Summary) bool {
 		return true
 	}
 
-	if s != nil && other == nil {
+	if s == nil || other == nil {
 		return false
 	}
 
diff --git a/table/snapshots_test.go b/table/snapshots_test.go
index 03bd3abdb..53f6bfff7 100644
--- a/table/snapshots_test.go
+++ b/table/snapshots_test.go
@@ -116,6 +116,24 @@ func TestInvalidOperation(t *testing.T) {
 	assert.ErrorContains(t, err, "found 'foobar'")
 }
 
+func TestSummaryEqualsHandlesNil(t *testing.T) {
+	var nilSummary *table.Summary
+	summary := &table.Summary{Operation: table.OpAppend}
+
+	assert.True(t, nilSummary.Equals(nil))
+	assert.False(t, nilSummary.Equals(summary))
+	assert.False(t, summary.Equals(nilSummary))
+}
+
+func TestSnapshotEqualsHandlesMissingSummary(t *testing.T) {
+	withSummary := Snapshot()
+	withoutSummary := withSummary
+	withoutSummary.Summary = nil
+
+	assert.False(t, withoutSummary.Equals(withSummary))
+	assert.False(t, withSummary.Equals(withoutSummary))
+}
+
 func TestSnapshotString(t *testing.T) {
 	snapshot := Snapshot()
 	assert.Equal(t, `append: id=25, parent_id=19, schema_id=3, sequence_number=200, timestamp_ms=1602638573590, manifest_list=s3:/a/b/c.avro`,