Skip to content

Commit 2bd9747

Browse files
authored
chore: move kInvalidSnapshotId to iceberg/constants.h (#456)
1 parent 53e15a9 commit 2bd9747

11 files changed

+16
-15
lines changed

src/iceberg/constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
#pragma once
2121

22+
#include <cstdint>
2223
#include <string_view>
2324

2425
namespace iceberg {
2526

2627
constexpr std::string_view kParquetFieldIdKey = "PARQUET:field_id";
28+
constexpr int64_t kInvalidSnapshotId = -1;
2729

2830
} // namespace iceberg

src/iceberg/inheritable_metadata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Result<std::unique_ptr<InheritableMetadata>> InheritableMetadataFactory::Empty()
9292
Result<std::unique_ptr<InheritableMetadata>> InheritableMetadataFactory::FromManifest(
9393
const ManifestFile& manifest) {
9494
// Validate that the manifest has a snapshot ID assigned
95-
if (manifest.added_snapshot_id == Snapshot::kInvalidSnapshotId) {
95+
if (manifest.added_snapshot_id == kInvalidSnapshotId) {
9696
return InvalidManifest("Manifest file {} has no snapshot ID", manifest.manifest_path);
9797
}
9898

src/iceberg/json_internal.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,9 @@ Result<std::unique_ptr<TableMetadata>> TableMetadataFromJson(const nlohmann::jso
10341034
}
10351035

10361036
// This field is optional, but internally we set this to -1 when not set
1037-
ICEBERG_ASSIGN_OR_RAISE(table_metadata->current_snapshot_id,
1038-
GetJsonValueOrDefault<int64_t>(json, kCurrentSnapshotId,
1039-
Snapshot::kInvalidSnapshotId));
1037+
ICEBERG_ASSIGN_OR_RAISE(
1038+
table_metadata->current_snapshot_id,
1039+
GetJsonValueOrDefault<int64_t>(json, kCurrentSnapshotId, kInvalidSnapshotId));
10401040

10411041
if (table_metadata->format_version >= 3) {
10421042
ICEBERG_ASSIGN_OR_RAISE(table_metadata->next_row_id,
@@ -1054,7 +1054,7 @@ Result<std::unique_ptr<TableMetadata>> TableMetadataFromJson(const nlohmann::jso
10541054
ICEBERG_ASSIGN_OR_RAISE(
10551055
table_metadata->refs,
10561056
FromJsonMap<std::shared_ptr<SnapshotRef>>(json, kRefs, SnapshotRefFromJson));
1057-
} else if (table_metadata->current_snapshot_id != Snapshot::kInvalidSnapshotId) {
1057+
} else if (table_metadata->current_snapshot_id != kInvalidSnapshotId) {
10581058
table_metadata->refs["main"] = std::make_unique<SnapshotRef>(SnapshotRef{
10591059
.snapshot_id = table_metadata->current_snapshot_id,
10601060
.retention = SnapshotRef::Branch{},

src/iceberg/manifest/manifest_list.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <string_view>
2828
#include <utility>
2929

30+
#include "iceberg/constants.h"
3031
#include "iceberg/iceberg_export.h"
3132
#include "iceberg/partition_spec.h"
3233
#include "iceberg/result.h"
@@ -106,7 +107,7 @@ struct ICEBERG_EXPORT ManifestFile {
106107
int64_t min_sequence_number = TableMetadata::kInitialSequenceNumber;
107108
/// Field id: 503
108109
/// ID of the snapshot where the manifest file was added
109-
int64_t added_snapshot_id = -1; // Snapshot::kInvalidSnapshotId
110+
int64_t added_snapshot_id = kInvalidSnapshotId;
110111
/// Field id: 504
111112
/// Number of entries in the manifest that have status ADDED (1), when null this is
112113
/// assumed to be non-zero

src/iceberg/manifest/manifest_writer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Result<ManifestFile> ManifestWriter::ToManifestFile() const {
238238
.sequence_number = TableMetadata::kInvalidSequenceNumber,
239239
.min_sequence_number =
240240
min_sequence_number_.value_or(TableMetadata::kInvalidSequenceNumber),
241-
.added_snapshot_id = adapter_->snapshot_id().value_or(Snapshot::kInvalidSnapshotId),
241+
.added_snapshot_id = adapter_->snapshot_id().value_or(kInvalidSnapshotId),
242242
.added_files_count = add_files_count_,
243243
.existing_files_count = existing_files_count_,
244244
.deleted_files_count = delete_files_count_,

src/iceberg/snapshot.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ struct ICEBERG_EXPORT DataOperation {
229229
///
230230
/// Snapshots are created by table operations.
231231
struct ICEBERG_EXPORT Snapshot {
232-
static constexpr int64_t kInvalidSnapshotId = -1;
233-
234232
/// A unique long ID.
235233
int64_t snapshot_id;
236234
/// The snapshot ID of the snapshot's parent. Omitted for any snapshot with no parent.

src/iceberg/table_metadata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ class TableMetadataBuilder::Impl {
533533
metadata_.last_column_id = Schema::kInvalidColumnId;
534534
metadata_.default_spec_id = PartitionSpec::kInitialSpecId;
535535
metadata_.last_partition_id = PartitionSpec::kInvalidPartitionFieldId;
536-
metadata_.current_snapshot_id = Snapshot::kInvalidSnapshotId;
536+
metadata_.current_snapshot_id = kInvalidSnapshotId;
537537
metadata_.default_sort_order_id = SortOrder::kInitialSortOrderId;
538538
metadata_.next_row_id = TableMetadata::kInitialRowId;
539539
}

src/iceberg/test/table_metadata_builder_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata() {
8383
metadata->partition_specs.push_back(PartitionSpec::Unpartitioned());
8484
metadata->default_spec_id = PartitionSpec::kInitialSpecId;
8585
metadata->last_partition_id = 0;
86-
metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
86+
metadata->current_snapshot_id = kInvalidSnapshotId;
8787
metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
8888
metadata->sort_orders.push_back(SortOrder::Unsorted());
8989
metadata->next_row_id = TableMetadata::kInitialRowId;
@@ -236,7 +236,7 @@ TEST(TableMetadataBuilderTest, BuildFromEmpty) {
236236
EXPECT_EQ(metadata->last_sequence_number, TableMetadata::kInitialSequenceNumber);
237237
EXPECT_EQ(metadata->default_spec_id, PartitionSpec::kInitialSpecId);
238238
EXPECT_EQ(metadata->default_sort_order_id, SortOrder::kUnsortedOrderId);
239-
EXPECT_EQ(metadata->current_snapshot_id, Snapshot::kInvalidSnapshotId);
239+
EXPECT_EQ(metadata->current_snapshot_id, kInvalidSnapshotId);
240240
EXPECT_TRUE(metadata->metadata_log.empty());
241241
}
242242

src/iceberg/test/table_requirements_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata(
5353
metadata->current_schema_id = Schema::kInitialSchemaId;
5454
metadata->default_spec_id = PartitionSpec::kInitialSpecId;
5555
metadata->last_partition_id = 0;
56-
metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
56+
metadata->current_snapshot_id = kInvalidSnapshotId;
5757
metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
5858
metadata->next_row_id = TableMetadata::kInitialRowId;
5959
return metadata;

src/iceberg/test/table_update_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata() {
7474
metadata->partition_specs.push_back(PartitionSpec::Unpartitioned());
7575
metadata->default_spec_id = PartitionSpec::kInitialSpecId;
7676
metadata->last_partition_id = 0;
77-
metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
77+
metadata->current_snapshot_id = kInvalidSnapshotId;
7878
metadata->sort_orders.push_back(SortOrder::Unsorted());
7979
metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
8080
metadata->next_row_id = TableMetadata::kInitialRowId;

0 commit comments

Comments
 (0)