laskoviymishka commented on code in PR #1201:
URL: https://github.com/apache/iceberg-go/pull/1201#discussion_r3423560488
##########
table/snapshot_producers.go:
##########
@@ -809,7 +809,10 @@ func (sp *snapshotProducer) summary(props
iceberg.Properties) (Summary, error) {
var previousSnapshot *Snapshot
if sp.parentSnapshotID > 0 {
- previousSnapshot, _ =
sp.txn.meta.SnapshotByID(sp.parentSnapshotID)
+ previousSnapshot, err =
sp.txn.meta.SnapshotByID(sp.parentSnapshotID)
+ if err != nil {
+ return Summary{}, fmt.Errorf("summary: lookup parent
snapshot %d: %w", sp.parentSnapshotID, err)
+ }
}
var previousSummary iceberg.Properties
Review Comment:
I think this fix surfaces a latent crash just below at the `previousSummary
= previousSnapshot.Summary.Properties` line.
`Summary` is `*Summary` with `omitempty`, so a V1 table or a parent snapshot
written without a summary can legally have it nil. Before this change a failed
lookup left `previousSnapshot` nil and the `if previousSnapshot != nil` guard
skipped the deref; now a successful lookup guarantees non-nil, so that line
panics unconditionally for those inputs. The old silent-zero bug was masking it.
I'd extend the guard the way line ~1066 already does: `if previousSnapshot
!= nil && previousSnapshot.Summary != nil`. wdyt?
##########
table/snapshot_producers_test.go:
##########
@@ -923,6 +923,54 @@ func TestComputeOwnManifests_NewTable(t *testing.T) {
require.Nil(t, got, "new table: returned manifests must equal input")
}
+// TestSummary_SnapshotByIDError verifies that summary computation fails when
+// the parent snapshot cannot be found, instead of silently treating totals as
+// starting from zero.
+func TestSummary_SnapshotByIDError(t *testing.T) {
Review Comment:
While we're here, neither new test covers the case that actually panics now
— parent present but `Summary == nil`. CI stays green while that crash ships.
I'd add a case injecting a parent snapshot with `Summary: nil` so the nil
guard above is regression-protected.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]