You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "fallintoplace (via GitHub)" <gi...@apache.org> on 2026/07/28 23:37:56 UTC

[PR] fix(table): validate last-updated-ms presence [iceberg-go]

fallintoplace opened a new pull request, #1591:
URL: https://github.com/apache/iceberg-go/pull/1591

   ## What changed
   
   Validate `last-updated-ms` against the deserialization sentinel used for an absent value. Add coverage for missing, null, and epoch-zero values across metadata format versions 1, 2, and 3.
   
   ## Why
   
   The decoder initialized an absent field to `-1`, but validation rejected `0`. Missing metadata therefore passed while a present Unix-epoch value was reported as missing.
   
   ## Testing
   
   - `go test ./table -run 'Test(LastUpdatedMSPresence|MetadataV[123]Parsing)$' -count=1`


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(table): validate last-updated-ms presence [iceberg-go]

Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka merged PR #1591:
URL: https://github.com/apache/iceberg-go/pull/1591


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(table): validate last-updated-ms presence [iceberg-go]

Posted by "tanmayrauth (via GitHub)" <gi...@apache.org>.
tanmayrauth commented on code in PR #1591:
URL: https://github.com/apache/iceberg-go/pull/1591#discussion_r3678294266


##########
table/metadata.go:
##########
@@ -1648,6 +1648,20 @@ func initCommonMetadataForDeserialization() commonMetadata {
 	}
 }
 
+func requireLastUpdatedMS(data []byte) error {

Review Comment:
   This re-parses the whole metadata document into map[string]json.RawMessage, but ParseMetadataBytes already builds exactly that map in assignMissingPartitionFieldIDs (metadata.go:1519) two steps before the struct unmarshal — so on the main load path the document now gets fully parsed into the same map type three times (once here per version). Beyond the redundant parse, this scatters the presence invariant across all three UnmarshalJSON methods. Consider asserting presence once in ParseMetadataBytes, reusing the map that assignMissingPartitionFieldIDs already has, so there's a single check for all format versions and no extra parse.



##########
table/metadata.go:
##########
@@ -2422,6 +2433,10 @@ func (m *metadataV1) preValidate() {
 }
 
 func (m *metadataV1) UnmarshalJSON(b []byte) error {
+	if err := requireLastUpdatedMS(b); err != nil {

Review Comment:
   Related to the above: this PR also removes the last-updated-ms case from commonMetadata.validate(), which is the shared invariant checker for both the JSON and builder paths. After this change validate() no longer asserts the field is set at all — the builder path is safe only because buildCommonMetadata forces
     time.Now() when lastUpdatedMS is 0 (metadata.go:1010). So the "must be present" invariant now lives incidentally in two spots (this unmarshal hook + the builder default) rather than in validate(). If the check moves into ParseMetadataBytes per the note above, that's fine; the thing to avoid is leaving validate()
     with no last-updated-ms assertion while the presence guarantee depends on two unrelated code paths.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(table): validate last-updated-ms presence [iceberg-go]

Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka commented on code in PR #1591:
URL: https://github.com/apache/iceberg-go/pull/1591#discussion_r3681135799


##########
table/metadata.go:
##########
@@ -1648,6 +1651,15 @@ func initCommonMetadataForDeserialization() commonMetadata {
 	}
 }
 
+func requireLastUpdatedMS(fields map[string]json.RawMessage) error {

Review Comment:
   this bare `return err` means a malformed-JSON blob comes back unwrapped, so `errors.Is(err, ErrInvalidMetadata)` is false for broken JSON but true for the null/missing case right below. Since this is a fresh call site I'd wrap it with `fmt.Errorf("%w: %w", ErrInvalidMetadata, err)` so callers get a consistent sentinel.



##########
table/metadata.go:
##########
@@ -1648,6 +1651,15 @@ func initCommonMetadataForDeserialization() commonMetadata {
 	}
 }
 
+func requireLastUpdatedMS(fields map[string]json.RawMessage) error {
+	value, ok := fields["last-updated-ms"]
+	if !ok || bytes.Equal(bytes.TrimSpace(value), []byte("null")) {
+		return fmt.Errorf("%w: missing last-updated-ms", ErrInvalidMetadata)
+	}

Review Comment:
   the `bytes.Equal(bytes.TrimSpace(value), []byte("null"))` is doing more work than it needs to. A `json.RawMessage` coming out of a `map[string]json.RawMessage` is already whitespace-trimmed by the decoder, so `string(value) == "null"` is equivalent and lets us drop the new `bytes` import entirely.
   
   ```suggestion
   	if !ok || string(value) == "null" {
   ```



##########
table/metadata.go:
##########
@@ -1648,6 +1651,15 @@ func initCommonMetadataForDeserialization() commonMetadata {
 	}
 }
 
+func requireLastUpdatedMS(fields map[string]json.RawMessage) error {
+	value, ok := fields["last-updated-ms"]
+	if !ok || bytes.Equal(bytes.TrimSpace(value), []byte("null")) {
+		return fmt.Errorf("%w: missing last-updated-ms", ErrInvalidMetadata)
+	}
+

Review Comment:
   small thing: this says "missing" but it also fires for an explicit `"last-updated-ms": null`, and the test asserts that exact substring for the null case, so the wording gets locked in. Something like `"last-updated-ms is absent or null"` (or just `"required"`) would be accurate for both paths.



##########
table/metadata_internal_test.go:
##########
@@ -310,6 +310,69 @@ func TestMetadataV3Parsing(t *testing.T) {
 	assert.Equal(t, int64(2000), *secondSnapshot.FirstRowID)
 }
 
+func TestLastUpdatedMSPresence(t *testing.T) {
+	tests := []struct {
+		name string
+		data string
+	}{
+		{name: "v1", data: ExampleTableMetadataV1},
+		{name: "v2", data: ExampleTableMetadataV2},
+		{name: "v3", data: ExampleTableMetadataV3},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			var metadata map[string]any

Review Comment:
   this map is declared once per version and then mutated in place by each inner subtest (missing/null/epoch/negative), so the cases only pass because they run in order. A `t.Parallel()` or `-shuffle` would have them stepping on each other. I'd `maps.Clone(metadata)` into a local at the top of each subtest so they're independent.



##########
table/metadata_internal_test.go:
##########
@@ -310,6 +310,69 @@ func TestMetadataV3Parsing(t *testing.T) {
 	assert.Equal(t, int64(2000), *secondSnapshot.FirstRowID)
 }
 
+func TestLastUpdatedMSPresence(t *testing.T) {
+	tests := []struct {
+		name string
+		data string
+	}{
+		{name: "v1", data: ExampleTableMetadataV1},
+		{name: "v2", data: ExampleTableMetadataV2},
+		{name: "v3", data: ExampleTableMetadataV3},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			var metadata map[string]any
+			require.NoError(t, json.Unmarshal([]byte(tt.data), &metadata))
+
+			for _, key := range []string{
+				"snapshots", "snapshot-log", "metadata-log", "current-snapshot-id",
+				"refs", "statistics", "partition-statistics",
+			} {
+				delete(metadata, key)
+			}
+
+			t.Run("missing", func(t *testing.T) {
+				delete(metadata, "last-updated-ms")
+				assertMissingLastUpdatedMS(t, metadata)
+			})
+
+			t.Run("null", func(t *testing.T) {
+				metadata["last-updated-ms"] = nil
+				assertMissingLastUpdatedMS(t, metadata)
+			})
+
+			t.Run("epoch", func(t *testing.T) {
+				metadata["last-updated-ms"] = float64(0)
+				raw, err := json.Marshal(metadata)
+				require.NoError(t, err)
+				parsed, err := ParseMetadataBytes(raw)
+				require.NoError(t, err)
+				assert.Zero(t, parsed.LastUpdatedMillis())
+			})
+
+			t.Run("negative", func(t *testing.T) {
+				metadata["last-updated-ms"] = float64(-1)
+				raw, err := json.Marshal(metadata)
+				require.NoError(t, err)
+				parsed, err := ParseMetadataBytes(raw)
+				require.NoError(t, err)
+				assert.Equal(t, int64(-1), parsed.LastUpdatedMillis())

Review Comment:
   the matrix covers missing/null/epoch/negative but not a present-but-wrong-type value like `"last-updated-ms": "2024-01-01"`. That case slips past `requireLastUpdatedMS` (present and non-null) and instead fails later with a `json.UnmarshalTypeError`, which isn't wrapped as `ErrInvalidMetadata`, so `errors.Is` holds for null but not for a wrong type. Worth a subtest that pins down which error we expect there. wdyt?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] fix(table): validate last-updated-ms presence [iceberg-go]

Posted by "haithemalsabr (via GitHub)" <gi...@apache.org>.
haithemalsabr commented on code in PR #1591:
URL: https://github.com/apache/iceberg-go/pull/1591#discussion_r3898044371


##########
table/metadata.go:
##########
@@ -1648,6 +1648,20 @@ func initCommonMetadataForDeserialization() commonMetadata {
 	}
 }
 
+func requireLastUpdatedMS(data []byte) error {

Review Comment:
   **الإسمالمستلم هيثم سعيديحيىأحمدالصبري**رقم الجوال 0096 777711 7998 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org