This is an automated email from the ASF dual-hosted git repository.

gangwu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 2bd9747a chore: move kInvalidSnapshotId to iceberg/constants.h (#456)
2bd9747a is described below

commit 2bd9747a9df7d0f985562906c3f00e4c6d6c37dc
Author: Junwang Zhao <[email protected]>
AuthorDate: Tue Dec 30 14:47:26 2025 +0800

    chore: move kInvalidSnapshotId to iceberg/constants.h (#456)
---
 src/iceberg/constants.h                         | 2 ++
 src/iceberg/inheritable_metadata.cc             | 2 +-
 src/iceberg/json_internal.cc                    | 8 ++++----
 src/iceberg/manifest/manifest_list.h            | 3 ++-
 src/iceberg/manifest/manifest_writer.cc         | 2 +-
 src/iceberg/snapshot.h                          | 2 --
 src/iceberg/table_metadata.cc                   | 2 +-
 src/iceberg/test/table_metadata_builder_test.cc | 4 ++--
 src/iceberg/test/table_requirements_test.cc     | 2 +-
 src/iceberg/test/table_update_test.cc           | 2 +-
 src/iceberg/test/update_partition_spec_test.cc  | 2 +-
 11 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/iceberg/constants.h b/src/iceberg/constants.h
index 61d10e2d..759ae3cc 100644
--- a/src/iceberg/constants.h
+++ b/src/iceberg/constants.h
@@ -19,10 +19,12 @@
 
 #pragma once
 
+#include <cstdint>
 #include <string_view>
 
 namespace iceberg {
 
 constexpr std::string_view kParquetFieldIdKey = "PARQUET:field_id";
+constexpr int64_t kInvalidSnapshotId = -1;
 
 }  // namespace iceberg
diff --git a/src/iceberg/inheritable_metadata.cc 
b/src/iceberg/inheritable_metadata.cc
index 081b90ac..1d740b5c 100644
--- a/src/iceberg/inheritable_metadata.cc
+++ b/src/iceberg/inheritable_metadata.cc
@@ -92,7 +92,7 @@ Result<std::unique_ptr<InheritableMetadata>> 
InheritableMetadataFactory::Empty()
 Result<std::unique_ptr<InheritableMetadata>> 
InheritableMetadataFactory::FromManifest(
     const ManifestFile& manifest) {
   // Validate that the manifest has a snapshot ID assigned
-  if (manifest.added_snapshot_id == Snapshot::kInvalidSnapshotId) {
+  if (manifest.added_snapshot_id == kInvalidSnapshotId) {
     return InvalidManifest("Manifest file {} has no snapshot ID", 
manifest.manifest_path);
   }
 
diff --git a/src/iceberg/json_internal.cc b/src/iceberg/json_internal.cc
index d175bb6d..4a36ebf2 100644
--- a/src/iceberg/json_internal.cc
+++ b/src/iceberg/json_internal.cc
@@ -1034,9 +1034,9 @@ Result<std::unique_ptr<TableMetadata>> 
TableMetadataFromJson(const nlohmann::jso
   }
 
   // This field is optional, but internally we set this to -1 when not set
-  ICEBERG_ASSIGN_OR_RAISE(table_metadata->current_snapshot_id,
-                          GetJsonValueOrDefault<int64_t>(json, 
kCurrentSnapshotId,
-                                                         
Snapshot::kInvalidSnapshotId));
+  ICEBERG_ASSIGN_OR_RAISE(
+      table_metadata->current_snapshot_id,
+      GetJsonValueOrDefault<int64_t>(json, kCurrentSnapshotId, 
kInvalidSnapshotId));
 
   if (table_metadata->format_version >= 3) {
     ICEBERG_ASSIGN_OR_RAISE(table_metadata->next_row_id,
@@ -1054,7 +1054,7 @@ Result<std::unique_ptr<TableMetadata>> 
TableMetadataFromJson(const nlohmann::jso
     ICEBERG_ASSIGN_OR_RAISE(
         table_metadata->refs,
         FromJsonMap<std::shared_ptr<SnapshotRef>>(json, kRefs, 
SnapshotRefFromJson));
-  } else if (table_metadata->current_snapshot_id != 
Snapshot::kInvalidSnapshotId) {
+  } else if (table_metadata->current_snapshot_id != kInvalidSnapshotId) {
     table_metadata->refs["main"] = std::make_unique<SnapshotRef>(SnapshotRef{
         .snapshot_id = table_metadata->current_snapshot_id,
         .retention = SnapshotRef::Branch{},
diff --git a/src/iceberg/manifest/manifest_list.h 
b/src/iceberg/manifest/manifest_list.h
index da70fb69..2f3185a1 100644
--- a/src/iceberg/manifest/manifest_list.h
+++ b/src/iceberg/manifest/manifest_list.h
@@ -27,6 +27,7 @@
 #include <string_view>
 #include <utility>
 
+#include "iceberg/constants.h"
 #include "iceberg/iceberg_export.h"
 #include "iceberg/partition_spec.h"
 #include "iceberg/result.h"
@@ -106,7 +107,7 @@ struct ICEBERG_EXPORT ManifestFile {
   int64_t min_sequence_number = TableMetadata::kInitialSequenceNumber;
   /// Field id: 503
   /// ID of the snapshot where the manifest file was added
-  int64_t added_snapshot_id = -1;  // Snapshot::kInvalidSnapshotId
+  int64_t added_snapshot_id = kInvalidSnapshotId;
   /// Field id: 504
   /// Number of entries in the manifest that have status ADDED (1), when null 
this is
   /// assumed to be non-zero
diff --git a/src/iceberg/manifest/manifest_writer.cc 
b/src/iceberg/manifest/manifest_writer.cc
index 52ad807e..c30f9f75 100644
--- a/src/iceberg/manifest/manifest_writer.cc
+++ b/src/iceberg/manifest/manifest_writer.cc
@@ -238,7 +238,7 @@ Result<ManifestFile> ManifestWriter::ToManifestFile() const 
{
       .sequence_number = TableMetadata::kInvalidSequenceNumber,
       .min_sequence_number =
           min_sequence_number_.value_or(TableMetadata::kInvalidSequenceNumber),
-      .added_snapshot_id = 
adapter_->snapshot_id().value_or(Snapshot::kInvalidSnapshotId),
+      .added_snapshot_id = 
adapter_->snapshot_id().value_or(kInvalidSnapshotId),
       .added_files_count = add_files_count_,
       .existing_files_count = existing_files_count_,
       .deleted_files_count = delete_files_count_,
diff --git a/src/iceberg/snapshot.h b/src/iceberg/snapshot.h
index a047c76b..3889607f 100644
--- a/src/iceberg/snapshot.h
+++ b/src/iceberg/snapshot.h
@@ -229,8 +229,6 @@ struct ICEBERG_EXPORT DataOperation {
 ///
 /// Snapshots are created by table operations.
 struct ICEBERG_EXPORT Snapshot {
-  static constexpr int64_t kInvalidSnapshotId = -1;
-
   /// A unique long ID.
   int64_t snapshot_id;
   /// The snapshot ID of the snapshot's parent. Omitted for any snapshot with 
no parent.
diff --git a/src/iceberg/table_metadata.cc b/src/iceberg/table_metadata.cc
index 114f3d0b..b6ce120f 100644
--- a/src/iceberg/table_metadata.cc
+++ b/src/iceberg/table_metadata.cc
@@ -533,7 +533,7 @@ class TableMetadataBuilder::Impl {
     metadata_.last_column_id = Schema::kInvalidColumnId;
     metadata_.default_spec_id = PartitionSpec::kInitialSpecId;
     metadata_.last_partition_id = PartitionSpec::kInvalidPartitionFieldId;
-    metadata_.current_snapshot_id = Snapshot::kInvalidSnapshotId;
+    metadata_.current_snapshot_id = kInvalidSnapshotId;
     metadata_.default_sort_order_id = SortOrder::kInitialSortOrderId;
     metadata_.next_row_id = TableMetadata::kInitialRowId;
   }
diff --git a/src/iceberg/test/table_metadata_builder_test.cc 
b/src/iceberg/test/table_metadata_builder_test.cc
index 84a272c8..40b728da 100644
--- a/src/iceberg/test/table_metadata_builder_test.cc
+++ b/src/iceberg/test/table_metadata_builder_test.cc
@@ -83,7 +83,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata() {
   metadata->partition_specs.push_back(PartitionSpec::Unpartitioned());
   metadata->default_spec_id = PartitionSpec::kInitialSpecId;
   metadata->last_partition_id = 0;
-  metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
+  metadata->current_snapshot_id = kInvalidSnapshotId;
   metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
   metadata->sort_orders.push_back(SortOrder::Unsorted());
   metadata->next_row_id = TableMetadata::kInitialRowId;
@@ -236,7 +236,7 @@ TEST(TableMetadataBuilderTest, BuildFromEmpty) {
   EXPECT_EQ(metadata->last_sequence_number, 
TableMetadata::kInitialSequenceNumber);
   EXPECT_EQ(metadata->default_spec_id, PartitionSpec::kInitialSpecId);
   EXPECT_EQ(metadata->default_sort_order_id, SortOrder::kUnsortedOrderId);
-  EXPECT_EQ(metadata->current_snapshot_id, Snapshot::kInvalidSnapshotId);
+  EXPECT_EQ(metadata->current_snapshot_id, kInvalidSnapshotId);
   EXPECT_TRUE(metadata->metadata_log.empty());
 }
 
diff --git a/src/iceberg/test/table_requirements_test.cc 
b/src/iceberg/test/table_requirements_test.cc
index c05e505f..80f83636 100644
--- a/src/iceberg/test/table_requirements_test.cc
+++ b/src/iceberg/test/table_requirements_test.cc
@@ -53,7 +53,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata(
   metadata->current_schema_id = Schema::kInitialSchemaId;
   metadata->default_spec_id = PartitionSpec::kInitialSpecId;
   metadata->last_partition_id = 0;
-  metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
+  metadata->current_snapshot_id = kInvalidSnapshotId;
   metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
   metadata->next_row_id = TableMetadata::kInitialRowId;
   return metadata;
diff --git a/src/iceberg/test/table_update_test.cc 
b/src/iceberg/test/table_update_test.cc
index 44a37f98..3cd0b722 100644
--- a/src/iceberg/test/table_update_test.cc
+++ b/src/iceberg/test/table_update_test.cc
@@ -74,7 +74,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata() {
   metadata->partition_specs.push_back(PartitionSpec::Unpartitioned());
   metadata->default_spec_id = PartitionSpec::kInitialSpecId;
   metadata->last_partition_id = 0;
-  metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
+  metadata->current_snapshot_id = kInvalidSnapshotId;
   metadata->sort_orders.push_back(SortOrder::Unsorted());
   metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
   metadata->next_row_id = TableMetadata::kInitialRowId;
diff --git a/src/iceberg/test/update_partition_spec_test.cc 
b/src/iceberg/test/update_partition_spec_test.cc
index 4da8f448..914a28e8 100644
--- a/src/iceberg/test/update_partition_spec_test.cc
+++ b/src/iceberg/test/update_partition_spec_test.cc
@@ -130,7 +130,7 @@ class UpdatePartitionSpecTest : public 
::testing::TestWithParam<int8_t> {
     metadata->schemas.push_back(std::move(schema));
     metadata->default_spec_id = spec->spec_id();
     metadata->last_partition_id = spec->last_assigned_field_id();
-    metadata->current_snapshot_id = Snapshot::kInvalidSnapshotId;
+    metadata->current_snapshot_id = kInvalidSnapshotId;
     metadata->default_sort_order_id = SortOrder::kUnsortedOrderId;
     metadata->sort_orders.push_back(SortOrder::Unsorted());
     metadata->next_row_id = TableMetadata::kInitialRowId;

Reply via email to