Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/iceberg/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/iceberg/inheritable_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/iceberg/json_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,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,
Expand All @@ -1053,7 +1053,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{},
Expand Down
3 changes: 2 additions & 1 deletion src/iceberg/manifest/manifest_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/manifest/manifest_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand Down
2 changes: 0 additions & 2 deletions src/iceberg/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/table_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/iceberg/test/table_metadata_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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;
Expand Down Expand Up @@ -234,7 +234,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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/test/table_requirements_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/test/table_update_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/test/update_partition_spec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading