Skip to content

Commit 75a8f90

Browse files
committed
Fix: Perform the lookup and validation of snapshot_id before the equality check
1 parent 0d1d9b8 commit 75a8f90

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/iceberg/util/snapshot_util.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ Result<bool> SnapshotUtil::IsAncestorOf(const TableMetadata& metadata,
8585
Result<bool> SnapshotUtil::IsAncestorOf(
8686
int64_t snapshot_id, int64_t ancestor_snapshot_id,
8787
const std::function<Result<std::shared_ptr<Snapshot>>(int64_t)>& lookup) {
88+
// Validate snapshot exists before equality check to match Java behavior
89+
ICEBERG_ASSIGN_OR_RAISE(auto current, lookup(snapshot_id));
90+
ICEBERG_CHECK(current != nullptr, "Cannot find snapshot: {}", snapshot_id);
91+
8892
if (snapshot_id == ancestor_snapshot_id) {
8993
return true;
9094
}
9195

92-
ICEBERG_ASSIGN_OR_RAISE(auto current, lookup(snapshot_id));
93-
ICEBERG_CHECK(current != nullptr, "Cannot find snapshot: {}", snapshot_id);
94-
9596
while (current != nullptr && current->parent_snapshot_id.has_value()) {
9697
int64_t parent_id = current->parent_snapshot_id.value();
9798
auto parent_result = lookup(parent_id);

0 commit comments

Comments
 (0)