Skip to content

Commit

Permalink
add some snapshot-id validation
Browse files Browse the repository at this point in the history
  • Loading branch information
snazy committed Dec 4, 2024
1 parent 27af5d1 commit e9d0abd
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.projectnessie.catalog.formats.iceberg.rest;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
Expand Down Expand Up @@ -483,6 +484,19 @@ default void applyToTable(IcebergTableMetadataUpdateState state) {
state.addCatalogOp(CatalogOps.META_ADD_SNAPSHOT);
Map<String, String> summary = snapshot().summary();

Long currentSnapshotId = state.snapshot().icebergSnapshotId();
Long parentSnapshotId = snapshot().parentSnapshotId();
checkArgument(
parentSnapshotId == null || Objects.equals(currentSnapshotId, parentSnapshotId),
"Snapshot to be added must use the parent snapshot ID %s or null, but provided parent snapshot ID is %s",
currentSnapshotId,
parentSnapshotId);
checkArgument(
(currentSnapshotId == null || snapshot().snapshotId() != currentSnapshotId)
&& !state.snapshot().previousIcebergSnapshotIds().contains(snapshot().snapshotId()),
"Provided snapshot ID %s is already used",
snapshot().snapshotId());

String v = summary.get("added-data-files");
if (v != null && Long.parseLong(v) > 0) {
state.addCatalogOp(CatalogOps.SNAP_ADD_DATA_FILES);
Expand Down

0 comments on commit e9d0abd

Please sign in to comment.