Skip to content

Conversation

@lliangyu-lin
Copy link
Contributor

@github-actions github-actions bot added the core label Apr 17, 2025
@nastra nastra self-requested a review April 17, 2025 06:10
changes.add(new MetadataUpdate.SetCurrentViewVersion(newVersionId));
}

// Use the timestamp from the view version if it was added in current set of changes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would slightly update/simplify this to

       // Use the timestamp from the view version if it was added in current set of changes;
       // otherwise, use the current system time. This handles cases where the view version
-      // was created in a past commit and is being re-activated.
+      // was set as current in the past and is being re-activated.
       boolean versionAddedInThisChange =
-          changes.stream()
-              .anyMatch(
-                  change ->
-                      change instanceof MetadataUpdate.AddViewVersion
-                          && ((MetadataUpdate.AddViewVersion) change).viewVersion().versionId()
-                              == newVersionId);
-
-      long timestamp =
-          versionAddedInThisChange ? version.timestampMillis() : System.currentTimeMillis();
+          changes(MetadataUpdate.AddViewVersion.class)
+              .anyMatch(added -> added.viewVersion().versionId() == newVersionId);

       this.historyEntry =
           ImmutableViewHistoryEntry.builder()
-              .timestampMillis(timestamp)
+              .timestampMillis(
+                  versionAddedInThisChange ? version.timestampMillis() : System.currentTimeMillis())
               .versionId(version.versionId())
               .build();

Copy link
Contributor Author

@lliangyu-lin lliangyu-lin Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nastra Thanks for the review! I'll apply the comments and raise a revision.
But some concerns I have right now is that the change breaks existing unit tests like

ViewMetadata expectedViewMetadata =
ViewMetadata.buildFrom(
ViewMetadata.buildFrom(
ViewMetadata.builder()
.assignUUID("fa6506c3-7681-40c8-86dc-e36561f83385")
.addSchema(TEST_SCHEMA)
.addVersion(version1)
.addVersion(version2)
.setLocation("s3://bucket/test/location")
.setProperties(
ImmutableMap.of(
"some-key",
"some-value",
ViewProperties.COMMENT,
"some-comment"))
.setCurrentVersionId(1)
.upgradeFormatVersion(1)
.build())
.setCurrentVersionId(2)
.build())
.setMetadataLocation(metadataLocation)
.build();

In .setCurrentVersionId(2), it's in different builder and have no local changes, causing the activation of view version to set to current timestamp even though version 2 never set as current before. And in the comment, we are trying to say only view version was set as current in the past will use current ts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the unit test with the changes you have here in order to match the version-log that we compare against (we compare against a fixed timestamp defined in ValidViewMetadata.json) makes sense to me as this is a consequence of using the current time millis instead of the view version's time when setting the view version from 1 to 2 without actually adding view version 2 in the same builder.

@lliangyu-lin lliangyu-lin requested a review from nastra April 21, 2025 19:04
Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @lliangyu-lin

@nastra nastra merged commit 01fe380 into apache:main Apr 25, 2025
42 checks passed
@lliangyu-lin lliangyu-lin deleted the view-history-log-timestamp branch April 25, 2025 17:35
@RussellSpitzer RussellSpitzer added this to the Iceberg 1.9.1 milestone May 12, 2025
RussellSpitzer pushed a commit to RussellSpitzer/iceberg that referenced this pull request May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View's VersionLog uses wrong timestamp if ViewVersions are reused

4 participants