badalprasadsingh commented on code in PR #2563:
URL: https://github.com/apache/iceberg-go/pull/2563#discussion_r4564052611


##########
table/snapshots.go:
##########
@@ -320,6 +320,12 @@ func (s *Snapshot) UnmarshalJSON(data []byte) error {
        // The pointer fields shadow Alias, so json.Unmarshal does not populate 
next.
        next.SnapshotID, next.TimestampMs = *aux.SnapshotID, *aux.TimestampMs
 
+       // Without either manifest source, scans would treat a malformed 
snapshot as empty.
+       // An explicitly empty manifests array is valid for legacy v1 snapshots.
+       if next.ManifestList == "" && next.ManifestLocations == nil {
+               return fmt.Errorf("%w: snapshot requires manifest-list or 
manifests", ErrInvalidMetadata)
+       }

Review Comment:
   P1: `ParseMetadataBytesDeferredSnapshots` (REST commit responses with 
snapshot-loading-mode=refs) skips this check, the same JSON loads there, then 
`Snapshots()` returns nothing, `SnapshotByID` returns nil and marshaling fails
   
   the allSnapshots comment calls that error unreachable, I'd share one check 
and also call it in `prepareDeferredSnapshots`



##########
table/snapshot_manifest_source_test.go:
##########
@@ -0,0 +1,80 @@
+// 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 (
+       "encoding/json"
+       "os"
+       "testing"
+
+       "github.com/apache/iceberg-go/table"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestSnapshotUnmarshalRequiresManifestSource(t *testing.T) {
+       tests := []struct {
+               name string
+               data string
+       }{
+               {"missing both", `{"snapshot-id": 25, "timestamp-ms": 
1602638573590}`},
+               {"null manifest list", `{"snapshot-id": 25, "timestamp-ms": 
1602638573590, "manifest-list": null}`},
+               {"empty manifest list", `{"snapshot-id": 25, "timestamp-ms": 
1602638573590, "manifest-list": ""}`},
+               {"null embedded manifests", `{"snapshot-id": 25, 
"timestamp-ms": 1602638573590, "manifests": null}`},
+               {"both null", `{"snapshot-id": 25, "timestamp-ms": 
1602638573590, "manifest-list": null, "manifests": null}`},
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       original := table.Snapshot{
+                               SnapshotID:   9,
+                               TimestampMs:  10,
+                               ManifestList: "s3://bucket/existing.avro",
+                       }
+                       snapshot := original
+
+                       err := json.Unmarshal([]byte(tt.data), &snapshot)
+                       require.ErrorIs(t, err, table.ErrInvalidMetadata)
+                       assert.ErrorContains(t, err, "manifest-list or 
manifests")
+                       assert.Equal(t, original, snapshot, "failed decode must 
preserve the receiver")
+               })
+       }
+}
+
+func TestParseMetadataRejectsSnapshotWithoutManifestSource(t *testing.T) {

Review Comment:
   no test parses this with ParseMetadataBytesDeferredSnapshots
   
   better: add a case where a snapshot no branch or tag points to has no 
source, and assert both parsers return the same ErrInvalidMetadata error, like 
TestDeferredSnapshotsMissingLastSequenceNumberErrorParity



##########
table/snapshot_manifest_source_test.go:
##########
@@ -0,0 +1,80 @@
+// 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 (
+       "encoding/json"
+       "os"
+       "testing"
+
+       "github.com/apache/iceberg-go/table"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestSnapshotUnmarshalRequiresManifestSource(t *testing.T) {

Review Comment:
   nit: no need of creating this new file: `snapshots_test.go` already has 
table tests for this: TestSnapshotUnmarshalRequiresSnapshotIDAndTimestamp, 
TestSnapshotUnmarshalFailureLeavesSnapshotUnchanged and 
TestParseMetadataRejectsSnapshotMissingRequiredFieldsI'd
   
   add these cases as rows there (renaming the first) and drop this file.



##########
website/src/releases.md:
##########
@@ -46,6 +46,7 @@ Per-release notes (highlights, breaking changes, 
contributors) are published on
 - **SigV4 keeps the token or credential as `Original-Authorization`.** With 
`rest.sigv4-enabled=true` (or `rest.auth.type=sigv4`) and a `token` or 
`credential`, requests used to be signed with the token silently dropped, 
because the SigV4 signature replaced the `Authorization` header. They now carry 
it as `Original-Authorization`, included in the signed headers, as Iceberg Java 
does. A server behind SigV4 that ignores the header is unaffected.
 - **Float and double literal comparators use Iceberg ordering.** 
`TypedLiteral.Comparator()` now orders `-0.0` before `+0.0` and NaN after all 
other values; NaN compares equal to NaN. Callers that use these public 
comparators may see a different order or equality result.
 - **Table creation rejects duplicate field IDs.** `NewMetadata`, and 
`CreateTable` on catalogs that build metadata through it (not REST), now return 
`ErrInvalidSchema` when two fields in the schema share an ID, including unset 
`0` or `-1` IDs, even for unpartitioned, unsorted tables. Before, the partition 
spec or sort order could bind to the wrong column. Callers should assign unique 
IDs (or let the schema be built with fresh IDs). This matches Java, whose 
`Schema` constructor rejects duplicate IDs.
+- **Snapshots require a manifest source.** Metadata snapshots without a 
non-empty `manifest-list` or a `manifests` array now fail to load. Previously, 
the missing source could be treated as an empty snapshot and hide table data 
from scans.

Review Comment:
   the whole table fails to load with ErrInvalidMetadata, even when only an old 
snapshot is bad, and this release can't remove it
   
   better: say that, and add a way out: remove such snapshots with an earlier 
release before upgrading



##########
table/snapshots.go:
##########
@@ -320,6 +320,12 @@ func (s *Snapshot) UnmarshalJSON(data []byte) error {
        // The pointer fields shadow Alias, so json.Unmarshal does not populate 
next.
        next.SnapshotID, next.TimestampMs = *aux.SnapshotID, *aux.TimestampMs
 
+       // Without either manifest source, scans would treat a malformed 
snapshot as empty.
+       // An explicitly empty manifests array is valid for legacy v1 snapshots.
+       if next.ManifestList == "" && next.ManifestLocations == nil {
+               return fmt.Errorf("%w: snapshot requires manifest-list or 
manifests", ErrInvalidMetadata)

Review Comment:
   nit: the error doesn't name the snapshot, which is hard to find in a long 
history -> add the id



##########
table/snapshots.go:
##########
@@ -320,6 +320,12 @@ func (s *Snapshot) UnmarshalJSON(data []byte) error {
        // The pointer fields shadow Alias, so json.Unmarshal does not populate 
next.
        next.SnapshotID, next.TimestampMs = *aux.SnapshotID, *aux.TimestampMs
 
+       // Without either manifest source, scans would treat a malformed 
snapshot as empty.

Review Comment:
   we can still write this: `MetadataBuilder.AddSnapshot` accepts a snapshot 
with neither source, so CommitTable succeeds and, with this PR, the next 
LoadTable fails, and so does any later commit
   
   #2567 blocks it for v2/v3 only -> could #2567 also reject v1 snapshots with 
neither source, and land first?



-- 
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]

Reply via email to