iceberg-cpp
Loading...
Searching...
No Matches
snapshot_util_internal.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <functional>
23#include <memory>
24#include <optional>
25#include <string>
26#include <vector>
27
28#include "iceberg/iceberg_export.h"
29#include "iceberg/result.h"
30#include "iceberg/type_fwd.h"
31#include "iceberg/util/timepoint.h"
32
33namespace iceberg {
34
37class ICEBERG_EXPORT SnapshotUtil {
38 public:
44 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsOf(const Table& table,
45 int64_t snapshot_id);
46
52 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsOf(
53 const TableMetadata& metadata, int64_t snapshot_id);
54
60 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsOf(
61 int64_t snapshot_id,
62 const std::function<Result<std::shared_ptr<Snapshot>>(int64_t)>& lookup);
63
70 static Result<bool> IsAncestorOf(const Table& table, int64_t ancestor_snapshot_id);
71
78 static Result<bool> IsAncestorOf(const TableMetadata& metadata,
79 int64_t ancestor_snapshot_id);
80
87 static Result<bool> IsAncestorOf(const Table& table, int64_t snapshot_id,
88 int64_t ancestor_snapshot_id);
89
96 static Result<bool> IsAncestorOf(const TableMetadata& metadata, int64_t snapshot_id,
97 int64_t ancestor_snapshot_id);
98
106 static Result<bool> IsAncestorOf(
107 int64_t snapshot_id, int64_t ancestor_snapshot_id,
108 const std::function<Result<std::shared_ptr<Snapshot>>(int64_t)>& lookup);
109
117 static Result<bool> IsParentAncestorOf(const Table& table, int64_t snapshot_id,
118 int64_t ancestor_parent_snapshot_id);
119
127 static Result<bool> IsParentAncestorOf(const TableMetadata& metadata,
128 int64_t snapshot_id,
129 int64_t ancestor_parent_snapshot_id);
130
138 static Result<bool> IsParentAncestorOf(
139 int64_t snapshot_id, int64_t ancestor_parent_snapshot_id,
140 const std::function<Result<std::shared_ptr<Snapshot>>(int64_t)>& lookup);
141
147 static Result<std::vector<std::shared_ptr<Snapshot>>> CurrentAncestors(
148 const Table& table);
149
155 static Result<std::vector<std::shared_ptr<Snapshot>>> CurrentAncestors(
156 const TableMetadata& metadata);
157
166 static Result<std::vector<int64_t>> CurrentAncestorIds(const Table& table);
167
173 static Result<std::optional<std::shared_ptr<Snapshot>>> OldestAncestor(
174 const Table& table);
175
186 static Result<std::optional<std::shared_ptr<Snapshot>>> OldestAncestorOf(
187 const Table& table, int64_t snapshot_id);
188
199 static Result<std::optional<std::shared_ptr<Snapshot>>> OldestAncestorOf(
200 const TableMetadata& metadata, int64_t snapshot_id);
201
210 static Result<std::optional<std::shared_ptr<Snapshot>>> OldestAncestorAfter(
211 const Table& table, TimePointMs timestamp_ms);
212
221 static Result<std::vector<int64_t>> SnapshotIdsBetween(const Table& table,
222 int64_t from_snapshot_id,
223 int64_t to_snapshot_id);
224
232 static Result<std::vector<int64_t>> AncestorIdsBetween(
233 const Table& table, int64_t latest_snapshot_id,
234 const std::optional<int64_t>& oldest_snapshot_id);
235
243 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsBetween(
244 const Table& table, int64_t latest_snapshot_id,
245 std::optional<int64_t> oldest_snapshot_id);
246
254 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsBetween(
255 const TableMetadata& metadata, int64_t latest_snapshot_id,
256 std::optional<int64_t> oldest_snapshot_id);
257
264 static Result<std::shared_ptr<Snapshot>> SnapshotAfter(const Table& table,
265 int64_t snapshot_id);
266
272 static Result<int64_t> SnapshotIdAsOfTime(const Table& table, TimePointMs timestamp_ms);
273
279 static Result<int64_t> SnapshotIdAsOfTime(const TableMetadata& metadata,
280 TimePointMs timestamp_ms);
281
288 static std::optional<int64_t> OptionalSnapshotIdAsOfTime(const Table& table,
289 TimePointMs timestamp_ms);
290
296 static Result<std::shared_ptr<Schema>> SchemaFor(const Table& table,
297 int64_t snapshot_id);
298
304 static Result<std::shared_ptr<Schema>> SchemaFor(const Table& table,
305 TimePointMs timestamp_ms);
306
316 static Result<std::shared_ptr<Schema>> SchemaFor(const Table& table,
317 const std::string& ref);
318
328 static Result<std::shared_ptr<Schema>> SchemaFor(const TableMetadata& metadata,
329 const std::string& ref);
330
340 static Result<std::shared_ptr<Snapshot>> LatestSnapshot(const Table& table,
341 const std::string& branch);
342
356 static Result<std::shared_ptr<Snapshot>> LatestSnapshot(const TableMetadata& metadata,
357 const std::string& branch);
358
368 static Result<std::shared_ptr<Snapshot>> OptionalLatestSnapshot(
369 const TableMetadata& metadata, const std::string& branch);
370
372 static int64_t GenerateSnapshotId();
373
378 static int64_t GenerateSnapshotId(const TableMetadata& metadata);
379
380 private:
386 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsOf(
387 const TableMetadata& metadata, const std::shared_ptr<Snapshot>& snapshot);
388
394 static Result<std::vector<std::shared_ptr<Snapshot>>> AncestorsOf(
395 const std::shared_ptr<Snapshot>& snapshot,
396 const std::function<Result<std::shared_ptr<Snapshot>>(int64_t)>& lookup);
397
402 static Result<std::vector<int64_t>> ToIds(
403 const std::vector<std::shared_ptr<Snapshot>>& snapshots);
404};
405
406} // namespace iceberg
Utility functions for working with snapshots.
Definition snapshot_util_internal.h:37
Represents an Iceberg table.
Definition table.h:38
Represents the metadata for an Iceberg table.
Definition table_metadata.h:72