File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
core/src/main/java/org/apache/iceberg Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -282,14 +282,18 @@ public void commit() {
282282 .run (taskOps -> {
283283 Snapshot newSnapshot = apply ();
284284 newSnapshotId .set (newSnapshot .snapshotId ());
285- TableMetadata updated ;
286- if (stageOnly ) {
287- updated = base .addStagedSnapshot (newSnapshot );
285+ TableMetadata .Builder update = TableMetadata .buildFrom (base );
286+ if (base .snapshot (newSnapshot .snapshotId ()) != null ) {
287+ // this is a rollback or cherrypick operation
288+ update .setCurrentSnapshot (newSnapshot .snapshotId ());
289+ } else if (stageOnly ) {
290+ update .addSnapshot (newSnapshot );
288291 } else {
289- updated = base . replaceCurrentSnapshot (newSnapshot );
292+ update . setCurrentSnapshot (newSnapshot );
290293 }
291294
292- if (updated == base ) {
295+ TableMetadata updated = update .build ();
296+ if (updated .changes ().isEmpty ()) {
293297 // do not commit if the metadata has not changed. for example, this may happen when setting the current
294298 // snapshot to an ID that is already current. note that this check uses identity.
295299 return ;
Original file line number Diff line number Diff line change @@ -501,6 +501,10 @@ public TableMetadata replaceCurrentSnapshot(Snapshot snapshot) {
501501 return new Builder (this ).setCurrentSnapshot (snapshot ).build ();
502502 }
503503
504+ public TableMetadata replaceCurrentSnapshot (long snapshotId ) {
505+ return new Builder (this ).setCurrentSnapshot (snapshotId ).build ();
506+ }
507+
504508 public TableMetadata removeSnapshotsIf (Predicate <Snapshot > removeIf ) {
505509 List <Snapshot > toRemove = snapshots .stream ().filter (removeIf ).collect (Collectors .toList ());
506510 return new Builder (this ).removeSnapshots (toRemove ).build ();
You can’t perform that action at this time.
0 commit comments