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

wgtmac 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 5740b95c feat(inspect): add manifests metadata table (#1121)
5740b95c is described below

commit 5740b95c4467247cd76b28277d5f49abb439ecda
Author: Manu Zhang <[email protected]>
AuthorDate: Wed Nov 25 13:06:42 2026 +0800

    feat(inspect): add manifests metadata table (#1121)
---
 src/iceberg/CMakeLists.txt                       |   1 +
 src/iceberg/cpp20_compatibility_internal.h       |   1 +
 src/iceberg/inspect/manifests_table.cc           | 254 ++++++++++++
 src/iceberg/inspect/manifests_table.h            |  58 +++
 src/iceberg/inspect/metadata_table.cc            |   3 +
 src/iceberg/test/CMakeLists.txt                  |   3 +-
 src/iceberg/test/inspect/manifests_table_test.cc | 490 +++++++++++++++++++++++
 src/iceberg/test/transform_human_string_test.cc  |   6 +
 src/iceberg/test/transform_util_test.cc          |   6 +
 src/iceberg/transform.cc                         |   4 +
 src/iceberg/type_fwd.h                           |   1 +
 src/iceberg/util/transform_util.cc               |  25 +-
 12 files changed, 839 insertions(+), 13 deletions(-)

diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt
index 0065b838..d4590201 100644
--- a/src/iceberg/CMakeLists.txt
+++ b/src/iceberg/CMakeLists.txt
@@ -59,6 +59,7 @@ set(ICEBERG_SOURCES
     incremental_append_scan.cc
     incremental_changelog_scan.cc
     inspect/history_table.cc
+    inspect/manifests_table.cc
     inspect/metadata_scan.cc
     inspect/metadata_table.cc
     inspect/metadata_scan_task.cc
diff --git a/src/iceberg/cpp20_compatibility_internal.h 
b/src/iceberg/cpp20_compatibility_internal.h
index d9c64d36..ef7ac765 100644
--- a/src/iceberg/cpp20_compatibility_internal.h
+++ b/src/iceberg/cpp20_compatibility_internal.h
@@ -81,6 +81,7 @@
 #include "iceberg/incremental_changelog_scan.h"
 #include "iceberg/inheritable_metadata.h"
 #include "iceberg/inspect/history_table.h"
+#include "iceberg/inspect/manifests_table.h"
 #include "iceberg/inspect/metadata_scan.h"
 #include "iceberg/inspect/metadata_scan_task.h"
 #include "iceberg/inspect/metadata_scan_task_reader.h"
diff --git a/src/iceberg/inspect/manifests_table.cc 
b/src/iceberg/inspect/manifests_table.cc
new file mode 100644
index 00000000..1e8cd960
--- /dev/null
+++ b/src/iceberg/inspect/manifests_table.cc
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/inspect/manifests_table.h"
+
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow_row_builder_internal.h"
+#include "iceberg/expression/literal.h"
+#include "iceberg/inspect/metadata_scan_util_internal.h"
+#include "iceberg/inspect/metadata_table_util_internal.h"
+#include "iceberg/logging/log_macros.h"
+#include "iceberg/manifest/manifest_list.h"
+#include "iceberg/nanoarrow_status_internal.h"
+#include "iceberg/partition_field.h"
+#include "iceberg/partition_spec.h"
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transform.h"
+#include "iceberg/type.h"
+#include "iceberg/util/checked_cast.h"
+#include "iceberg/util/conversions.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+namespace {
+
+struct ManifestRow {
+  ManifestFile manifest;
+  std::shared_ptr<PartitionSpec> spec;
+  std::shared_ptr<StructType> partition_type;
+};
+
+Status AppendPartitionBound(ArrowArray* array, const PartitionField& field,
+                            const std::shared_ptr<Type>& type,
+                            const std::optional<std::vector<uint8_t>>& bound) {
+  if (!bound.has_value() || type->type_id() == TypeId::kUnknown) {
+    return AppendString(array, "null");
+  }
+  auto primitive = internal::checked_pointer_cast<PrimitiveType>(type);
+  ICEBERG_ASSIGN_OR_RAISE(auto literal,
+                          Conversions::FromBytes(std::move(primitive), 
*bound));
+  ICEBERG_ASSIGN_OR_RAISE(auto text, 
field.transform()->ToHumanString(literal));
+  return AppendString(array, text);
+}
+
+Status AppendPartitionSummaries(ArrowArray* array, const ManifestRow& row) {
+  const auto spec_fields = row.spec->fields();
+  const auto& result_fields = row.partition_type->fields();
+  ICEBERG_PRECHECK(row.manifest.partitions.size() <= spec_fields.size() &&
+                       row.manifest.partitions.size() <= result_fields.size(),
+                   "Manifest '{}' has more partition summaries than spec {} 
fields",
+                   row.manifest.manifest_path, row.spec->spec_id());
+  auto* entries = array->children[0];
+  ICEBERG_PRECHECK(entries != nullptr && entries->n_children == 4,
+                   "Partition summaries must contain four fields");
+
+  for (size_t index = 0; index < row.manifest.partitions.size(); ++index) {
+    const auto& summary = row.manifest.partitions[index];
+    ICEBERG_RETURN_UNEXPECTED(AppendBoolean(entries->children[0], 
summary.contains_null));
+    if (summary.contains_nan.has_value()) {
+      ICEBERG_RETURN_UNEXPECTED(
+          AppendBoolean(entries->children[1], *summary.contains_nan));
+    } else {
+      ICEBERG_RETURN_UNEXPECTED(AppendNull(entries->children[1]));
+    }
+
+    const auto& field = spec_fields[index];
+    const auto& type = result_fields[index].type();
+    if (type->type_id() == TypeId::kUnknown &&
+        (summary.lower_bound.has_value() || summary.upper_bound.has_value())) {
+      ICEBERG_LOG_WARN(
+          "Cannot render partition bounds with unknown type in manifest '{}' "
+          "(spec {}, field '{}' ({}), source column {})",
+          row.manifest.manifest_path, row.spec->spec_id(), field.name(), 
field.field_id(),
+          field.source_id());
+    }
+    ICEBERG_RETURN_UNEXPECTED(
+        AppendPartitionBound(entries->children[2], field, type, 
summary.lower_bound));
+    ICEBERG_RETURN_UNEXPECTED(
+        AppendPartitionBound(entries->children[3], field, type, 
summary.upper_bound));
+    ICEBERG_NANOARROW_RETURN_UNEXPECTED(ArrowArrayFinishElement(entries));
+  }
+  ICEBERG_NANOARROW_RETURN_UNEXPECTED(ArrowArrayFinishElement(array));
+  return {};
+}
+
+template <std::optional<int32_t> ManifestFile::* CountField, ManifestContent 
Content>
+Status AppendManifestCount(ArrowArray* array, const ManifestRow& row) {
+  const auto& manifest = row.manifest;
+  if (manifest.content == Content) {
+    const auto& count = manifest.*CountField;
+    return count.has_value() ? AppendInt(array, *count) : AppendNull(array);
+  } else {
+    return AppendInt(array, 0);
+  }
+}
+
+constexpr std::array<internal::MetadataTableColumn<ManifestRow>, 12> 
kManifestColumns = {{
+    {.field_id = 14,
+     .append =
+         [](ArrowArray* array, const ManifestRow& row) {
+           return AppendInt(array, static_cast<int64_t>(row.manifest.content));
+         }},
+    {.field_id = 1,
+     .append =
+         [](ArrowArray* array, const ManifestRow& row) {
+           return AppendString(array, row.manifest.manifest_path);
+         }},
+    {.field_id = 2,
+     .append =
+         [](ArrowArray* array, const ManifestRow& row) {
+           return AppendInt(array, row.manifest.manifest_length);
+         }},
+    {.field_id = 3,
+     .append =
+         [](ArrowArray* array, const ManifestRow& row) {
+           return AppendInt(array, row.manifest.partition_spec_id);
+         }},
+    {.field_id = 4,
+     .append = [](ArrowArray* array, const ManifestRow& row) -> Status {
+       ICEBERG_PRECHECK(row.manifest.added_snapshot_id.has_value(),
+                        "Manifest '{}' has no added snapshot ID",
+                        row.manifest.manifest_path);
+       return AppendInt(array, *row.manifest.added_snapshot_id);
+     }},
+    {.field_id = 5,
+     .append =
+         AppendManifestCount<&ManifestFile::added_files_count, 
ManifestContent::kData>},
+    {.field_id = 6,
+     .append = AppendManifestCount<&ManifestFile::existing_files_count,
+                                   ManifestContent::kData>},
+    {.field_id = 7,
+     .append =
+         AppendManifestCount<&ManifestFile::deleted_files_count, 
ManifestContent::kData>},
+    {.field_id = 15,
+     .append = AppendManifestCount<&ManifestFile::added_files_count,
+                                   ManifestContent::kDeletes>},
+    {.field_id = 16,
+     .append = AppendManifestCount<&ManifestFile::existing_files_count,
+                                   ManifestContent::kDeletes>},
+    {.field_id = 17,
+     .append = AppendManifestCount<&ManifestFile::deleted_files_count,
+                                   ManifestContent::kDeletes>},
+    {.field_id = 8, .append = AppendPartitionSummaries},
+}};
+
+}  // namespace
+
+ManifestsTable::ManifestsTable(std::shared_ptr<const Table> table)
+    : MetadataTable(std::move(table)) {}
+
+ManifestsTable::~ManifestsTable() = default;
+
+std::shared_ptr<Schema> ManifestsTable::schema() const {
+  static const auto schema = std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(14, "content", int32()),
+      SchemaField::MakeRequired(1, "path", string()),
+      SchemaField::MakeRequired(2, "length", int64()),
+      SchemaField::MakeRequired(3, "partition_spec_id", int32()),
+      SchemaField::MakeRequired(4, "added_snapshot_id", int64()),
+      // Legacy manifests can omit counts; unknown counts must stay null.
+      SchemaField::MakeOptional(5, "added_data_files_count", int32()),
+      SchemaField::MakeOptional(6, "existing_data_files_count", int32()),
+      SchemaField::MakeOptional(7, "deleted_data_files_count", int32()),
+      SchemaField::MakeOptional(15, "added_delete_files_count", int32()),
+      SchemaField::MakeOptional(16, "existing_delete_files_count", int32()),
+      SchemaField::MakeOptional(17, "deleted_delete_files_count", int32()),
+      SchemaField::MakeRequired(
+          8, "partition_summaries",
+          list(SchemaField::MakeRequired(
+              9, std::string(ListType::kElementName),
+              struct_({SchemaField::MakeRequired(10, "contains_null", 
boolean()),
+                       SchemaField::MakeOptional(11, "contains_nan", 
boolean()),
+                       SchemaField::MakeOptional(12, "lower_bound", string()),
+                       SchemaField::MakeOptional(13, "upper_bound", 
string())})))),
+  });
+  return schema;
+}
+
+Result<std::unique_ptr<ManifestsTable>> ManifestsTable::Make(
+    std::shared_ptr<const Table> table) {
+  ICEBERG_PRECHECK(table != nullptr, "Table cannot be null");
+  return std::unique_ptr<ManifestsTable>(new ManifestsTable(std::move(table)));
+}
+
+Result<std::unique_ptr<MetadataScan>> ManifestsTable::MakeScan(
+    internal::MetadataScanContext context, std::shared_ptr<FileIO> io) const {
+  return internal::MakeSnapshotMetadataScan(std::move(context), std::move(io), 
ReadRows);
+}
+
+Result<ArrowArrayStream> ManifestsTable::ReadRows(
+    const internal::MetadataScanContext& context, const 
std::shared_ptr<FileIO>& io,
+    int64_t batch_size) {
+  ICEBERG_ASSIGN_OR_RAISE(auto snapshot, 
internal::ResolveMetadataTableSnapshot(
+                                             *context.table_metadata, 
context));
+  std::vector<ManifestRow> rows;
+  std::unordered_map<int32_t, std::shared_ptr<StructType>> partition_types;
+  if (snapshot != nullptr) {
+    ICEBERG_ASSIGN_OR_RAISE(auto table_schema, 
context.table_metadata->Schema());
+    SnapshotReader snapshot_reader(snapshot.get());
+    ICEBERG_ASSIGN_OR_RAISE(auto manifests, snapshot_reader.Manifests(io));
+    rows.reserve(manifests.size());
+    for (const auto& manifest : manifests) {
+      ICEBERG_ASSIGN_OR_RAISE(auto spec, 
context.table_metadata->PartitionSpecById(
+                                             manifest.partition_spec_id));
+      auto [entry, inserted] = partition_types.try_emplace(spec->spec_id());
+      if (inserted) {
+        ICEBERG_ASSIGN_OR_RAISE(entry->second, 
spec->PartitionType(*table_schema));
+      }
+      rows.push_back(ManifestRow{.manifest = manifest,
+                                 .spec = std::move(spec),
+                                 .partition_type = entry->second});
+    }
+  }
+
+  const size_t num_rows = rows.size();
+  return internal::MakeMetadataBatchStream<ManifestRow>(
+      context.schema, context.projected_schema, kManifestColumns, num_rows, 
batch_size,
+      [rows = std::move(rows)](size_t index) -> const ManifestRow& {
+        return rows[index];
+      });
+}
+
+}  // namespace iceberg
diff --git a/src/iceberg/inspect/manifests_table.h 
b/src/iceberg/inspect/manifests_table.h
new file mode 100644
index 00000000..750deb12
--- /dev/null
+++ b/src/iceberg/inspect/manifests_table.h
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/inspect/manifests_table.h
+/// \brief Define the manifests metadata table.
+
+#include <memory>
+
+#include "iceberg/arrow_c_data.h"
+#include "iceberg/iceberg_export.h"
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+
+namespace iceberg {
+
+/// \brief Metadata table containing manifest-list entries for a snapshot.
+class ICEBERG_EXPORT ManifestsTable : public MetadataTable {
+ public:
+  static Result<std::unique_ptr<ManifestsTable>> Make(std::shared_ptr<const 
Table> table);
+
+  ~ManifestsTable() override;
+
+  Kind kind() const noexcept override { return Kind::kManifests; }
+
+  std::shared_ptr<Schema> schema() const override;
+
+ protected:
+  Result<std::unique_ptr<MetadataScan>> MakeScan(
+      internal::MetadataScanContext context, std::shared_ptr<FileIO> io) const 
override;
+
+ private:
+  static Result<ArrowArrayStream> ReadRows(const 
internal::MetadataScanContext& context,
+                                           const std::shared_ptr<FileIO>& io,
+                                           int64_t batch_size);
+
+  explicit ManifestsTable(std::shared_ptr<const Table> table);
+};
+
+}  // namespace iceberg
diff --git a/src/iceberg/inspect/metadata_table.cc 
b/src/iceberg/inspect/metadata_table.cc
index 57d8cdad..26ec23b3 100644
--- a/src/iceberg/inspect/metadata_table.cc
+++ b/src/iceberg/inspect/metadata_table.cc
@@ -23,6 +23,7 @@
 #include <utility>
 
 #include "iceberg/inspect/history_table.h"
+#include "iceberg/inspect/manifests_table.h"
 #include "iceberg/inspect/metadata_scan.h"
 #include "iceberg/inspect/refs_table.h"
 #include "iceberg/inspect/snapshots_table.h"
@@ -43,6 +44,8 @@ Result<std::unique_ptr<MetadataTable>> MetadataTable::Make(
       return RefsTable::Make(std::move(table));
     case MetadataTableKind::kHistory:
       return HistoryTable::Make(std::move(table));
+    case MetadataTableKind::kManifests:
+      return ManifestsTable::Make(std::move(table));
     default:
       break;
   }
diff --git a/src/iceberg/test/CMakeLists.txt b/src/iceberg/test/CMakeLists.txt
index a6f3d8ba..70c31275 100644
--- a/src/iceberg/test/CMakeLists.txt
+++ b/src/iceberg/test/CMakeLists.txt
@@ -235,7 +235,8 @@ if(ICEBERG_BUILD_BUNDLE)
                    inspect/history_table_test.cc
                    inspect/metadata_table_test.cc
                    inspect/refs_table_test.cc
-                   inspect/snapshots_table_test.cc)
+                   inspect/snapshots_table_test.cc
+                   inspect/manifests_table_test.cc)
 
   add_iceberg_test(eval_expr_test
                    USE_BUNDLE
diff --git a/src/iceberg/test/inspect/manifests_table_test.cc 
b/src/iceberg/test/inspect/manifests_table_test.cc
new file mode 100644
index 00000000..bd8c042c
--- /dev/null
+++ b/src/iceberg/test/inspect/manifests_table_test.cc
@@ -0,0 +1,490 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/inspect/manifests_table.h"
+
+#include <cstdint>
+#include <format>
+#include <memory>
+#include <optional>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/arrow/arrow_io_util.h"
+#include "iceberg/constants.h"
+#include "iceberg/inspect/metadata_scan.h"
+#include "iceberg/inspect/metadata_scan_task_reader.h"
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/logging/logger.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/manifest/manifest_list.h"
+#include "iceberg/partition_spec.h"
+#include "iceberg/row/partition_values.h"
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_identifier.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/test/logging_test_helpers.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/mock_catalog.h"
+#include "iceberg/test/scan_test_base.h"
+#include "iceberg/transform.h"
+#include "iceberg/type.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/timepoint.h"
+
+namespace iceberg {
+namespace {
+
+class ManifestsTableTest : public ScanTestBase {
+ protected:
+  Result<std::shared_ptr<Table>> MakeTable(
+      const std::vector<std::shared_ptr<Snapshot>>& snapshots,
+      int64_t current_snapshot_id, std::shared_ptr<PartitionSpec> spec = 
nullptr) {
+    auto metadata =
+        MakeTableMetadata(snapshots, current_snapshot_id, {}, std::move(spec));
+    return Table::Make(
+        TableIdentifier{.ns = Namespace{.levels = {"db"}}, .name = "table"},
+        std::move(metadata), "s3://bucket/metadata.json", file_io_, catalog_);
+  }
+
+  static Result<ArrowArrayStream> Scan(const MetadataTable& table) {
+    ICEBERG_ASSIGN_OR_RAISE(auto builder, table.NewScan());
+    ICEBERG_ASSIGN_OR_RAISE(auto scan, builder->Build());
+    return scan->ToArrowArrayStream();
+  }
+
+  static Result<std::vector<std::shared_ptr<::arrow::RecordBatch>>> 
ReadAllBatches(
+      ArrowArrayStream&& stream) {
+    auto reader = ::arrow::ImportRecordBatchReader(&stream);
+    if (!reader.ok()) {
+      return InvalidArrowData(reader.status().ToString());
+    }
+    auto batches = reader.ValueUnsafe()->ToRecordBatches();
+    if (!batches.ok()) {
+      return InvalidArrowData(batches.status().ToString());
+    }
+    return std::move(batches).MoveValueUnsafe();
+  }
+
+  Status RefreshTableSchemaAndPartitionSpec(const std::shared_ptr<Table>& 
table,
+                                            const std::shared_ptr<Snapshot>& 
first) {
+    auto old_schema = schema_;
+    schema_ = std::make_shared<Schema>(
+        std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int32()),
+                                 SchemaField::MakeRequired(2, "data", 
string()),
+                                 SchemaField::MakeOptional(3, "extra", 
int64())},
+        1);
+    std::shared_ptr<PartitionSpec> new_spec;
+    ICEBERG_ASSIGN_OR_RAISE(
+        new_spec,
+        PartitionSpec::Make(
+            2, {PartitionField(2, 1000, "data_bucket_16_2", 
Transform::Bucket(16)),
+                PartitionField(1, 1001, "id", Transform::Identity())}));
+    auto second = MakeAppendSnapshotWithPartitionValues(
+        GetParam(), 20, 10, 2,
+        {{"one.parquet", PartitionValues({Literal::Int(7), Literal::Int(1)})},
+         {"two.parquet", PartitionValues({Literal::Int(7), Literal::Int(2)})}},
+        new_spec);
+    auto metadata = MakeTableMetadata({first, second}, 20, {}, new_spec);
+    metadata->schemas.insert(metadata->schemas.begin(), old_schema);
+    metadata->partition_specs.push_back(new_spec);
+    metadata->last_column_id = 3;
+    metadata->last_partition_id = 1001;
+    ICEBERG_ASSIGN_OR_RAISE(
+        auto refreshed,
+        Table::Make(table->name(), std::move(metadata), 
"s3://bucket/refreshed.json",
+                    arrow::MakeMockFileIO(), catalog_));
+    EXPECT_CALL(*catalog_, LoadTable(::testing::_))
+        .WillOnce(::testing::Return(refreshed));
+    return table->Refresh();
+  }
+
+  const std::shared_ptr<MockCatalog> catalog_ = 
std::make_shared<MockCatalog>();
+};
+
+TEST_P(ManifestsTableTest, Scan) {
+  auto snapshot = MakeAppendSnapshotWithPartitionValues(
+      GetParam(), 10, std::nullopt, 1,
+      {{"s3://bucket/data.parquet", PartitionValues(Literal::Int(7))}},
+      partitioned_spec_);
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({snapshot}, 10, 
partitioned_spec_));
+
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, 
MetadataTable::Make<ManifestsTable>(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests_stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests_batches,
+                         ReadAllBatches(std::move(manifests_stream)));
+  ASSERT_EQ(manifests_batches.size(), 1);
+  ASSERT_EQ(manifests_batches[0]->num_rows(), 1);
+  auto manifest_paths = std::static_pointer_cast<::arrow::StringArray>(
+      manifests_batches[0]->GetColumnByName("path"));
+  auto added_files = std::static_pointer_cast<::arrow::Int32Array>(
+      manifests_batches[0]->GetColumnByName("added_data_files_count"));
+  EXPECT_FALSE(manifest_paths->GetString(0).empty());
+  EXPECT_EQ(added_files->Value(0), 1);
+}
+
+TEST_P(ManifestsTableTest, CountsMatchManifestContent) {
+  auto data_manifest = WriteDataManifest(
+      GetParam(), 10,
+      {MakeEntry(ManifestStatus::kAdded, 10, 1, 
MakeDataFile("data.parquet"))});
+  auto delete_file = MakeDataFile("delete.parquet");
+  delete_file->content = DataFile::Content::kEqualityDeletes;
+  delete_file->equality_ids = {1};
+  auto delete_manifest = WriteDeleteManifest(
+      GetParam(), 10, {MakeEntry(ManifestStatus::kAdded, 10, 1, 
std::move(delete_file))},
+      unpartitioned_spec_);
+  auto snapshot = std::make_shared<Snapshot>(Snapshot{
+      .snapshot_id = 10,
+      .sequence_number = 1,
+      .timestamp_ms = TimePointMsFromUnixMs(1000),
+      .manifest_list =
+          WriteManifestList(GetParam(), 10, 0, 1, {data_manifest, 
delete_manifest}),
+  });
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({snapshot}, 10));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, ManifestsTable::Make(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  const auto& batch = batches.front();
+  ASSERT_EQ(batch->num_rows(), 2);
+  auto content = 
std::static_pointer_cast<::arrow::Int32Array>(batch->column(0));
+  EXPECT_EQ(content->Value(0), static_cast<int32_t>(ManifestContent::kData));
+  EXPECT_EQ(content->Value(1), 
static_cast<int32_t>(ManifestContent::kDeletes));
+  for (int index = 5; index <= 10; ++index) {
+    SCOPED_TRACE(batch->schema()->field(index)->name());
+    auto counts = 
std::static_pointer_cast<::arrow::Int32Array>(batch->column(index));
+    EXPECT_EQ(counts->null_count(), 0);
+    EXPECT_EQ(counts->Value(0), index == 5 ? 1 : 0);
+    EXPECT_EQ(counts->Value(1), index == 8 ? 1 : 0);
+  }
+}
+
+TEST_P(ManifestsTableTest, PreservesUnknownManifestCounts) {
+  // Upgraded tables can still reference v1 manifest lists, where counts are 
optional.
+  auto unknown = WriteDataManifest(
+      1, 10, {MakeEntry(ManifestStatus::kAdded, 10, 0, 
MakeDataFile("data.parquet"))});
+  unknown.added_files_count.reset();
+  unknown.existing_files_count.reset();
+  unknown.deleted_files_count.reset();
+  auto empty = WriteDataManifest(1, 10, {});
+  auto snapshot = std::make_shared<Snapshot>(Snapshot{
+      .snapshot_id = 10,
+      .sequence_number = 0,
+      .timestamp_ms = TimePointMsFromUnixMs(1000),
+      .manifest_list = WriteManifestList(1, 10, 0, 0, {unknown, empty}),
+  });
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({snapshot}, 10));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, 
MetadataTable::Make<ManifestsTable>(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  ASSERT_EQ(batches[0]->num_rows(), 2);
+  for (int index = 5; index <= 10; ++index) {
+    auto counts =
+        
std::static_pointer_cast<::arrow::Int32Array>(batches[0]->column(index));
+    if (index < 8) {
+      EXPECT_TRUE(counts->IsNull(0));
+    } else {
+      // Delete counts are definitively zero in a data manifest.
+      EXPECT_FALSE(counts->IsNull(0));
+      EXPECT_EQ(counts->Value(0), 0);
+    }
+    // A known zero must remain distinguishable from an unknown count.
+    EXPECT_FALSE(counts->IsNull(1));
+    EXPECT_EQ(counts->Value(1), 0);
+    EXPECT_TRUE(batches[0]->schema()->field(index)->nullable());
+    EXPECT_TRUE(manifests->schema()->fields()[index].optional());
+  }
+}
+
+TEST_P(ManifestsTableTest, ManifestNullBoundsUseJavaRendering) {
+  auto snapshot = MakeAppendSnapshotWithPartitionValues(
+      GetParam(), 10, std::nullopt, 1,
+      {{"null.parquet", PartitionValues(Literal::Null(int32()))}}, 
partitioned_spec_);
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({snapshot}, 10, 
partitioned_spec_));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, 
MetadataTable::Make<ManifestsTable>(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  auto summaries = std::static_pointer_cast<::arrow::ListArray>(
+      batches[0]->GetColumnByName("partition_summaries"));
+  auto values = 
std::static_pointer_cast<::arrow::StructArray>(summaries->values());
+  ASSERT_EQ(values->length(), 1);
+  for (int index : {2, 3}) {
+    auto bound = 
std::static_pointer_cast<::arrow::StringArray>(values->field(index));
+    ASSERT_FALSE(bound->IsNull(0));
+    EXPECT_EQ(bound->GetString(0), "null");
+  }
+}
+
+TEST_P(ManifestsTableTest, FloatingPointBoundsRoundTrip) {
+  schema_ = std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(1, "f32", float32()),
+      SchemaField::MakeRequired(2, "f64", float64()),
+  });
+  ICEBERG_UNWRAP_OR_FAIL(
+      partitioned_spec_,
+      PartitionSpec::Make(1, {PartitionField(1, 1000, "f32", 
Transform::Identity()),
+                              PartitionField(2, 1001, "f64", 
Transform::Identity())}));
+  auto snapshot = MakeAppendSnapshotWithPartitionValues(
+      GetParam(), 10, std::nullopt, 1,
+      {{"low.parquet", PartitionValues({Literal::Float(1e-7F), 
Literal::Double(1e-7)})},
+       {"high.parquet", PartitionValues({Literal::Float(2e-7F), 
Literal::Double(2e-7)})}},
+      partitioned_spec_);
+  auto metadata = MakeTableMetadata({snapshot}, 10, {}, partitioned_spec_);
+  metadata->last_partition_id = 1001;
+  ICEBERG_UNWRAP_OR_FAIL(
+      auto table, Table::Make(TableIdentifier{.name = "table"}, 
std::move(metadata),
+                              "s3://bucket/metadata.json", file_io_, 
catalog_));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, ManifestsTable::Make(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  auto summaries = std::static_pointer_cast<::arrow::ListArray>(
+      batches[0]->GetColumnByName("partition_summaries"));
+  auto values = 
std::static_pointer_cast<::arrow::StructArray>(summaries->values());
+  ASSERT_EQ(values->length(), 2);
+  auto lower = 
std::static_pointer_cast<::arrow::StringArray>(values->field(2));
+  auto upper = 
std::static_pointer_cast<::arrow::StringArray>(values->field(3));
+  EXPECT_EQ(std::stof(lower->GetString(0)), 1e-7F);
+  EXPECT_EQ(std::stof(upper->GetString(0)), 2e-7F);
+  EXPECT_EQ(std::stod(lower->GetString(1)), 1e-7);
+  EXPECT_EQ(std::stod(upper->GetString(1)), 2e-7);
+}
+
+TEST_P(ManifestsTableTest, ManifestBoundsSurviveDroppedBucketSource) {
+  auto snapshot = MakeAppendSnapshotWithPartitionValues(
+      GetParam(), 10, std::nullopt, 1,
+      {{"data.parquet", PartitionValues(Literal::Int(7))}}, partitioned_spec_);
+  auto metadata = MakeTableMetadata({snapshot}, 10);
+  metadata->schemas.push_back(std::make_shared<Schema>(
+      std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int32())}, 
1));
+  metadata->current_schema_id = 1;
+  ICEBERG_UNWRAP_OR_FAIL(
+      auto table, Table::Make(TableIdentifier{.name = "table"}, 
std::move(metadata),
+                              "s3://bucket/metadata.json", file_io_, 
catalog_));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, 
MetadataTable::Make<ManifestsTable>(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  auto summaries = std::static_pointer_cast<::arrow::ListArray>(
+      batches[0]->GetColumnByName("partition_summaries"));
+  auto values = 
std::static_pointer_cast<::arrow::StructArray>(summaries->values());
+  ASSERT_EQ(values->length(), 1);
+  for (int index : {2, 3}) {
+    auto bound = 
std::static_pointer_cast<::arrow::StringArray>(values->field(index));
+    ASSERT_FALSE(bound->IsNull(0));
+    EXPECT_EQ(bound->GetString(0), "7");
+  }
+}
+
+TEST_P(ManifestsTableTest, ManifestBoundsUsePromotedType) {
+  std::shared_ptr<PartitionSpec> spec;
+  ICEBERG_UNWRAP_OR_FAIL(
+      spec, PartitionSpec::Make(
+                1, {PartitionField(1, 1000, "id", Transform::Identity()),
+                    PartitionField(2, 1001, "data_prefix", 
Transform::Truncate(3))}));
+  auto write_manifest = [&](const std::string& path, Literal id) {
+    return WriteDataManifest(
+        GetParam(), 10,
+        {MakeEntry(
+            ManifestStatus::kAdded, 10, 1,
+            MakeDataFile(path, PartitionValues({std::move(id), 
Literal::String("abc")}),
+                         spec))},
+        spec);
+  };
+  auto original = schema_;
+  auto old_manifest = write_manifest("int.parquet", Literal::Int(7));
+  schema_ = std::make_shared<Schema>(
+      std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int64()),
+                               SchemaField::MakeRequired(2, "data", string())},
+      1);
+  auto new_manifest = write_manifest("long.parquet", 
Literal::Long(4294967296LL));
+  auto snapshot = std::make_shared<Snapshot>(Snapshot{
+      .snapshot_id = 10,
+      .sequence_number = 1,
+      .timestamp_ms = TimePointMsFromUnixMs(1000),
+      .manifest_list =
+          WriteManifestList(GetParam(), 10, 0, 1, {old_manifest, 
new_manifest}),
+  });
+  auto metadata = MakeTableMetadata({snapshot}, 10);
+  metadata->schemas.insert(metadata->schemas.begin(), original);
+  metadata->partition_specs = {unpartitioned_spec_, spec};
+  metadata->last_partition_id = 1001;
+  ICEBERG_UNWRAP_OR_FAIL(
+      auto table, Table::Make(TableIdentifier{.name = "table"}, 
std::move(metadata),
+                              "s3://bucket/metadata.json", file_io_, 
catalog_));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, ManifestsTable::Make(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  auto summaries = std::static_pointer_cast<::arrow::ListArray>(
+      batches[0]->GetColumnByName("partition_summaries"));
+  auto values = 
std::static_pointer_cast<::arrow::StructArray>(summaries->values());
+  ASSERT_EQ(values->length(), 4);
+  for (int index : {2, 3}) {
+    auto bounds = 
std::static_pointer_cast<::arrow::StringArray>(values->field(index));
+    EXPECT_EQ(bounds->GetString(0), "7");
+    EXPECT_EQ(bounds->GetString(1), "abc");
+    EXPECT_EQ(bounds->GetString(2), "4294967296");
+    EXPECT_EQ(bounds->GetString(3), "abc");
+  }
+}
+
+TEST_P(ManifestsTableTest, ManifestBoundsWithDroppedSourceUseJavaRendering) {
+  std::shared_ptr<PartitionSpec> spec;
+  ICEBERG_UNWRAP_OR_FAIL(
+      spec, PartitionSpec::Make(
+                1, {PartitionField(1, 1000, "id", Transform::Identity()),
+                    PartitionField(1, 1001, "id_bucket", 
Transform::Bucket(16)),
+                    PartitionField(2, 1002, "data_prefix", 
Transform::Truncate(3))}));
+  auto snapshot = MakeAppendSnapshotWithPartitionValues(
+      GetParam(), 10, std::nullopt, 1,
+      {{"data.parquet",
+        PartitionValues({Literal::Int(7), Literal::Int(3), 
Literal::String("abc")})}},
+      spec);
+  auto metadata = MakeTableMetadata({snapshot}, 10);
+  metadata->schemas.push_back(std::make_shared<Schema>(
+      std::vector<SchemaField>{SchemaField::MakeRequired(2, "data", 
string())}, 1));
+  metadata->current_schema_id = 1;
+  metadata->partition_specs = {unpartitioned_spec_, spec};
+  metadata->last_partition_id = 1002;
+  ICEBERG_UNWRAP_OR_FAIL(
+      auto table, Table::Make(TableIdentifier{.name = "table"}, 
std::move(metadata),
+                              "s3://bucket/metadata.json", file_io_, 
catalog_));
+  ICEBERG_UNWRAP_OR_FAIL(auto manifests, ManifestsTable::Make(table));
+
+  auto logger = std::make_shared<CapturingLogger>();
+  logger->SetLevel(LogLevel::kWarn);
+  ScopedLogger bind(logger);
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*manifests));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  ASSERT_EQ(batches.size(), 1);
+  auto summaries = std::static_pointer_cast<::arrow::ListArray>(
+      batches[0]->GetColumnByName("partition_summaries"));
+  auto values = 
std::static_pointer_cast<::arrow::StructArray>(summaries->values());
+  ASSERT_EQ(values->length(), 3);
+  for (int index : {2, 3}) {
+    auto bounds = 
std::static_pointer_cast<::arrow::StringArray>(values->field(index));
+    ASSERT_EQ(bounds->null_count(), 0);
+    EXPECT_EQ(bounds->GetString(0), "null");
+    EXPECT_EQ(bounds->GetString(1), "3");
+    EXPECT_EQ(bounds->GetString(2), "abc");
+  }
+
+  const auto warnings = logger->records();
+  ASSERT_EQ(warnings.size(), 1);
+  EXPECT_EQ(warnings[0].level, LogLevel::kWarn);
+  EXPECT_THAT(warnings[0].message,
+              ::testing::HasSubstr("spec 1, field 'id' (1000), source column 
1"));
+}
+
+TEST_P(ManifestsTableTest, ScanEmpty) {
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({}, kInvalidSnapshotId));
+  ICEBERG_UNWRAP_OR_FAIL(auto metadata_table, 
MetadataTable::Make<ManifestsTable>(table));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, Scan(*metadata_table));
+  ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(stream)));
+  EXPECT_TRUE(batches.empty());
+}
+
+TEST_P(ManifestsTableTest, 
TasksRetainProjectionAndMetadataWithCustomBatchSize) {
+  std::vector<ManifestFile> manifests;
+  for (int32_t index = 0; index < 3; ++index) {
+    manifests.push_back(WriteDataManifest(
+        GetParam(), 10,
+        {MakeEntry(
+            ManifestStatus::kAdded, 10, 1,
+            MakeDataFile(std::format("file-{}.parquet", index),
+                         PartitionValues(Literal::Int(index)), 
partitioned_spec_))},
+        partitioned_spec_));
+  }
+  auto first = std::make_shared<Snapshot>(
+      Snapshot{.snapshot_id = 10,
+               .sequence_number = 1,
+               .timestamp_ms = TimePointMsFromUnixMs(1000),
+               .manifest_list = WriteManifestList(GetParam(), 10, 0, 1, 
manifests)});
+  ICEBERG_UNWRAP_OR_FAIL(auto table, MakeTable({first}, 10, 
partitioned_spec_));
+  ICEBERG_UNWRAP_OR_FAIL(auto metadata_table,
+                         table->Inspect(MetadataTableKind::kManifests));
+  const auto canonical_schema = metadata_table->schema();
+  const auto& fields = canonical_schema->fields();
+  auto projection =
+      std::make_shared<Schema>(std::vector<SchemaField>{fields[1], fields[0]});
+  const std::string first_column(projection->fields()[0].name());
+  const std::string second_column(projection->fields()[1].name());
+  ICEBERG_UNWRAP_OR_FAIL(auto builder, metadata_table->NewScan());
+  ICEBERG_UNWRAP_OR_FAIL(auto empty_builder, metadata_table->NewScan());
+  ICEBERG_UNWRAP_OR_FAIL(auto invalid_builder, metadata_table->NewScan());
+  auto invalid_projection = std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(fields[0].field_id(), "wrong_type", int64())});
+  
EXPECT_FALSE(invalid_builder->Project(invalid_projection).Build().has_value());
+
+  // Builders retain metadata even when the source refreshes before Build().
+  ASSERT_THAT(RefreshTableSchemaAndPartitionSpec(table, first), IsOk());
+  ICEBERG_UNWRAP_OR_FAIL(auto scan, builder->Project(projection).Build());
+  ICEBERG_UNWRAP_OR_FAIL(auto empty_scan, empty_builder->Select({}).Build());
+  ICEBERG_UNWRAP_OR_FAIL(auto tasks, scan->PlanTasks());
+  ICEBERG_UNWRAP_OR_FAIL(auto empty_tasks, empty_scan->PlanTasks());
+  ASSERT_EQ(tasks.size(), 1);
+  ASSERT_EQ(empty_tasks.size(), 1);
+  builder.reset();
+  empty_builder.reset();
+  invalid_builder.reset();
+  scan.reset();
+  empty_scan.reset();
+  metadata_table.reset();
+  table.reset();
+
+  ICEBERG_UNWRAP_OR_FAIL(auto reader, 
MetadataScanTaskReader::Make({.batch_size = 2}));
+  ICEBERG_UNWRAP_OR_FAIL(auto stream, reader->Open(*tasks[0]));
+  ICEBERG_UNWRAP_OR_FAIL(auto repeat_stream, reader->Open(*tasks[0]));
+  ICEBERG_UNWRAP_OR_FAIL(auto empty_stream, reader->Open(*empty_tasks[0]));
+  reader.reset();
+  tasks.clear();
+  empty_tasks.clear();
+  for (auto* output : {&stream, &repeat_stream}) {
+    ICEBERG_UNWRAP_OR_FAIL(auto batches, ReadAllBatches(std::move(*output)));
+    ASSERT_EQ(batches.size(), 2);
+    EXPECT_EQ(batches[0]->num_rows(), 2);
+    EXPECT_EQ(batches[1]->num_rows(), 1);
+    ASSERT_EQ(batches[0]->num_columns(), 2);
+    EXPECT_EQ(batches[0]->schema()->field(0)->name(), first_column);
+    EXPECT_EQ(batches[0]->schema()->field(1)->name(), second_column);
+  }
+  ICEBERG_UNWRAP_OR_FAIL(auto empty_batches, 
ReadAllBatches(std::move(empty_stream)));
+  ASSERT_EQ(empty_batches.size(), 2);
+  EXPECT_EQ(empty_batches[0]->num_rows(), 2);
+  EXPECT_EQ(empty_batches[1]->num_rows(), 1);
+  EXPECT_EQ(empty_batches[0]->num_columns(), 0);
+}
+
+INSTANTIATE_TEST_SUITE_P(FormatVersions, ManifestsTableTest, 
::testing::Values(2, 3));
+
+}  // namespace
+}  // namespace iceberg
diff --git a/src/iceberg/test/transform_human_string_test.cc 
b/src/iceberg/test/transform_human_string_test.cc
index 28f4a484..85f29cfb 100644
--- a/src/iceberg/test/transform_human_string_test.cc
+++ b/src/iceberg/test/transform_human_string_test.cc
@@ -71,6 +71,12 @@ INSTANTIATE_TEST_SUITE_P(
         HumanStringTestParam{.test_name = "TimestampWithoutZone",
                              .literal = Literal::Timestamp(1512123175038194),
                              .expecteds{"2017-12-01T10:12:55.038194"}},
+        HumanStringTestParam{.test_name = "Float",
+                             .literal = Literal::Float(1.2345678F),
+                             .expecteds{"1.2345678"}},
+        HumanStringTestParam{.test_name = "Double",
+                             .literal = Literal::Double(1.2345678901234567),
+                             .expecteds{"1.2345678901234567"}},
         HumanStringTestParam{.test_name = "Long",
                              .literal = Literal::Long(-1234567890000L),
                              .expecteds{"-1234567890000"}},
diff --git a/src/iceberg/test/transform_util_test.cc 
b/src/iceberg/test/transform_util_test.cc
index 13c96b9e..957bb95b 100644
--- a/src/iceberg/test/transform_util_test.cc
+++ b/src/iceberg/test/transform_util_test.cc
@@ -19,6 +19,8 @@
 
 #include "iceberg/util/transform_util.h"
 
+#include <limits>
+
 #include <gtest/gtest.h>
 
 namespace iceberg {
@@ -138,6 +140,8 @@ TEST(TransformUtilTest, HumanTimestampWithZone) {
 }
 
 TEST(TransformUtilTest, HumanTimestampNs) {
+  EXPECT_EQ("1677-09-21T00:12:43.145224192",
+            
TransformUtil::HumanTimestampNs(std::numeric_limits<int64_t>::min()));
   EXPECT_EQ("1970-01-01T00:00:00.000000001", 
TransformUtil::HumanTimestampNs(1));
   EXPECT_EQ("2026-01-01T00:00:01.000001001",
             TransformUtil::HumanTimestampNs(1767225601000001001L));
@@ -145,6 +149,8 @@ TEST(TransformUtilTest, HumanTimestampNs) {
 }
 
 TEST(TransformUtilTest, HumanTimestampNsWithZone) {
+  EXPECT_EQ("1677-09-21T00:12:43.145224192+00:00",
+            
TransformUtil::HumanTimestampNsWithZone(std::numeric_limits<int64_t>::min()));
   EXPECT_EQ("1970-01-01T00:00:00.000000001+00:00",
             TransformUtil::HumanTimestampNsWithZone(1));
   EXPECT_EQ("2026-01-01T00:00:01.000001001+00:00",
diff --git a/src/iceberg/transform.cc b/src/iceberg/transform.cc
index 011e3d67..d243e6c5 100644
--- a/src/iceberg/transform.cc
+++ b/src/iceberg/transform.cc
@@ -457,6 +457,10 @@ Result<std::string> Transform::ToHumanString(const 
Literal& value) {
     case TransformType::kUnknown:
     case TransformType::kVoid: {
       switch (value.type()->type_id()) {
+        case TypeId::kFloat:
+          return std::format("{}", std::get<float>(value.value()));
+        case TypeId::kDouble:
+          return std::format("{}", std::get<double>(value.value()));
         case TypeId::kDate:
           return TransformUtil::HumanDay(std::get<int32_t>(value.value()));
         case TypeId::kTime:
diff --git a/src/iceberg/type_fwd.h b/src/iceberg/type_fwd.h
index 8e441d87..354495e3 100644
--- a/src/iceberg/type_fwd.h
+++ b/src/iceberg/type_fwd.h
@@ -286,6 +286,7 @@ class PositionDeleteIndex;
 enum class MetadataTableKind : uint8_t;
 
 class HistoryTable;
+class ManifestsTable;
 class MetadataScanBuilder;
 class MetadataTable;
 class MetadataScan;
diff --git a/src/iceberg/util/transform_util.cc 
b/src/iceberg/util/transform_util.cc
index 0a8af63c..f97d07d5 100644
--- a/src/iceberg/util/transform_util.cc
+++ b/src/iceberg/util/transform_util.cc
@@ -25,6 +25,15 @@
 #include "iceberg/util/temporal_util.h"
 
 namespace iceberg {
+namespace {
+
+// Converting the floored second back to ticks can overflow near INT64_MIN.
+int64_t SubsecondRemainder(int64_t ticks, int64_t ticks_per_second) {
+  const auto remainder = ticks % ticks_per_second;
+  return remainder < 0 ? remainder + ticks_per_second : remainder;
+}
+
+}  // namespace
 
 std::string TransformUtil::HumanYear(int32_t year_ordinal) {
   auto y = internal::kEpochYmd + std::chrono::years{year_ordinal};
@@ -68,9 +77,7 @@ std::string TransformUtil::HumanTimestamp(int64_t 
timestamp_micros) {
       std::chrono::floor<std::chrono::seconds>(micros_since_epoch);
   auto tp = std::chrono::time_point<std::chrono::system_clock, 
std::chrono::seconds>{
       seconds_since_epoch};
-  auto micros = 
std::chrono::duration_cast<std::chrono::microseconds>(micros_since_epoch -
-                                                                      
seconds_since_epoch)
-                    .count();
+  const auto micros = SubsecondRemainder(timestamp_micros, 
internal::kMicrosPerSecond);
   if (micros == 0) {
     return std::format("{:%FT%T}", tp);
   } else if (micros % internal::kMicrosPerMilli == 0) {
@@ -86,9 +93,7 @@ std::string TransformUtil::HumanTimestampNs(int64_t 
timestamp_nanos) {
       std::chrono::floor<std::chrono::seconds>(nanos_since_epoch);
   auto tp = std::chrono::time_point<std::chrono::system_clock, 
std::chrono::seconds>{
       seconds_since_epoch};
-  auto nanos = 
std::chrono::duration_cast<std::chrono::nanoseconds>(nanos_since_epoch -
-                                                                    
seconds_since_epoch)
-                   .count();
+  const auto nanos = SubsecondRemainder(timestamp_nanos, 
internal::kNanosPerSecond);
   if (nanos == 0) {
     return std::format("{:%FT%T}", tp);
   } else if (nanos % internal::kNanosPerMilli == 0) {
@@ -106,9 +111,7 @@ std::string TransformUtil::HumanTimestampWithZone(int64_t 
timestamp_micros) {
       std::chrono::floor<std::chrono::seconds>(micros_since_epoch);
   auto tp = std::chrono::time_point<std::chrono::system_clock, 
std::chrono::seconds>{
       seconds_since_epoch};
-  auto micros = 
std::chrono::duration_cast<std::chrono::microseconds>(micros_since_epoch -
-                                                                      
seconds_since_epoch)
-                    .count();
+  const auto micros = SubsecondRemainder(timestamp_micros, 
internal::kMicrosPerSecond);
   if (micros == 0) {
     return std::format("{:%FT%T}+00:00", tp);
   } else if (micros % internal::kMicrosPerMilli == 0) {
@@ -124,9 +127,7 @@ std::string TransformUtil::HumanTimestampNsWithZone(int64_t 
timestamp_nanos) {
       std::chrono::floor<std::chrono::seconds>(nanos_since_epoch);
   auto tp = std::chrono::time_point<std::chrono::system_clock, 
std::chrono::seconds>{
       seconds_since_epoch};
-  auto nanos = 
std::chrono::duration_cast<std::chrono::nanoseconds>(nanos_since_epoch -
-                                                                    
seconds_since_epoch)
-                   .count();
+  const auto nanos = SubsecondRemainder(timestamp_nanos, 
internal::kNanosPerSecond);
   if (nanos == 0) {
     return std::format("{:%FT%T}+00:00", tp);
   } else if (nanos % internal::kNanosPerMilli == 0) {

Reply via email to