Skip to content

Commit 219b030

Browse files
committed
fix: resolve more feedback
1 parent 2dc17d0 commit 219b030

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/iceberg/util/snapshot_util.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,15 @@ Result<std::vector<std::shared_ptr<Snapshot>>> SnapshotUtil::AncestorsOf(
4747
Result<bool> SnapshotUtil::IsAncestorOf(const Table& table, int64_t snapshot_id,
4848
int64_t ancestor_snapshot_id) {
4949
ICEBERG_ASSIGN_OR_RAISE(auto ancestors, AncestorsOf(table, snapshot_id));
50-
for (const auto& snapshot : ancestors) {
51-
if (snapshot->snapshot_id == ancestor_snapshot_id) {
52-
return true;
53-
}
54-
}
55-
return false;
50+
return std::ranges::any_of(ancestors, [ancestor_snapshot_id](const auto& snapshot) {
51+
return snapshot->snapshot_id == ancestor_snapshot_id;
52+
});
5653
}
5754

5855
Result<bool> SnapshotUtil::IsAncestorOf(const Table& table,
5956
int64_t ancestor_snapshot_id) {
6057
ICEBERG_ASSIGN_OR_RAISE(auto current, table.current_snapshot());
58+
ICEBERG_DCHECK(current, "Current snapshot is null");
6159
return IsAncestorOf(table, current->snapshot_id, ancestor_snapshot_id);
6260
}
6361

@@ -73,8 +71,14 @@ Result<bool> SnapshotUtil::IsParentAncestorOf(const Table& table, int64_t snapsh
7371

7472
Result<std::vector<std::shared_ptr<Snapshot>>> SnapshotUtil::CurrentAncestors(
7573
const Table& table) {
76-
ICEBERG_ASSIGN_OR_RAISE(auto current, table.current_snapshot());
77-
return AncestorsOf(table, current);
74+
auto current_result = table.current_snapshot();
75+
if (!current_result.has_value()) {
76+
if (current_result.error().kind == ErrorKind::kNotFound) {
77+
return std::vector<std::shared_ptr<Snapshot>>();
78+
}
79+
return std::unexpected<Error>(current_result.error());
80+
}
81+
return AncestorsOf(table, current_result.value());
7882
}
7983

8084
Result<std::vector<int64_t>> SnapshotUtil::CurrentAncestorIds(const Table& table) {
@@ -105,10 +109,7 @@ Result<std::optional<std::shared_ptr<Snapshot>>> SnapshotUtil::OldestAncestorAft
105109
auto current_result = table.current_snapshot();
106110
ICEBERG_RETURN_NULLOPT_IF_NOT_FOUND(current_result);
107111
auto current = current_result.value();
108-
if (!current) {
109-
// there are no snapshots or ancestors
110-
return std::nullopt;
111-
}
112+
ICEBERG_DCHECK(current, "Current snapshot is null");
112113

113114
std::optional<std::shared_ptr<Snapshot>> last_snapshot = std::nullopt;
114115
ICEBERG_ASSIGN_OR_RAISE(auto ancestors, AncestorsOf(table, current));

src/iceberg/util/snapshot_util_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ICEBERG_EXPORT SnapshotUtil {
7878
static Result<std::vector<std::shared_ptr<Snapshot>>> CurrentAncestors(
7979
const Table& table);
8080

81-
/// \brief Return the snapshot IDs for the ancestors of the current table state.
81+
/// \brief Returns the snapshot IDs for the ancestors of the current table state.
8282
///
8383
/// Ancestor IDs are ordered by commit time, descending. The first ID is the current
8484
/// snapshot, followed by its parent, and so on.

0 commit comments

Comments
 (0)