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 db796cbf fix: preserve partition types after source columns are
dropped (#999)
db796cbf is described below
commit db796cbf5d51bd74aa1cfba7647eae748d91ff05
Author: Manu Zhang <[email protected]>
AuthorDate: Tue Oct 13 14:48:15 2026 +0800
fix: preserve partition types after source columns are dropped (#999)
Co-authored-by: Codex <[email protected]>
---
src/iceberg/partition_spec.cc | 10 +++-------
src/iceberg/test/partition_spec_test.cc | 12 +++++++++---
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/iceberg/partition_spec.cc b/src/iceberg/partition_spec.cc
index 90be924b..29ff046c 100644
--- a/src/iceberg/partition_spec.cc
+++ b/src/iceberg/partition_spec.cc
@@ -82,13 +82,9 @@ Result<std::unique_ptr<StructType>>
PartitionSpec::PartitionType(
for (const auto& partition_field : fields_) {
ICEBERG_ASSIGN_OR_RAISE(auto source_field,
schema.FindFieldById(partition_field.source_id()));
- std::shared_ptr<Type> result_type;
- if (source_field.has_value()) {
- auto source_field_type = source_field.value().get().type();
- result_type =
partition_field.transform()->ResultType(std::move(source_field_type));
- } else {
- result_type = unknown();
- }
+ // Fixed-result transforms retain their type after the source column is
dropped.
+ auto source_type = source_field.has_value() ? source_field->get().type() :
unknown();
+ auto result_type = partition_field.transform()->ResultType(source_type);
partition_fields.emplace_back(partition_field.field_id(),
std::string(partition_field.name()),
diff --git a/src/iceberg/test/partition_spec_test.cc
b/src/iceberg/test/partition_spec_test.cc
index 9a31b065..f7919f60 100644
--- a/src/iceberg/test/partition_spec_test.cc
+++ b/src/iceberg/test/partition_spec_test.cc
@@ -171,17 +171,23 @@ TEST(PartitionSpecTest, PartitionTypeMissingSource) {
PartitionSpec::Make(
1, {PartitionField(1, 1000, "dropped_identity",
Transform::Identity()),
PartitionField(3, 1001, "dropped_bucket", Transform::Bucket(16)),
- PartitionField(2, 1002, "ts_day", Transform::Day())}));
+ PartitionField(2, 1002, "ts_day", Transform::Day()),
+ PartitionField(4, 1003, "dropped_day", Transform::Day()),
+ PartitionField(4, 1004, "dropped_year", Transform::Year())}));
ICEBERG_UNWRAP_OR_FAIL(auto partition_type, spec->PartitionType(schema));
- ASSERT_EQ(partition_type->fields().size(), 3U);
+ ASSERT_EQ(partition_type->fields().size(), 5U);
EXPECT_EQ(partition_type->fields()[0],
SchemaField::MakeOptional(1000, "dropped_identity", unknown()));
EXPECT_EQ(partition_type->fields()[1],
- SchemaField::MakeOptional(1001, "dropped_bucket", unknown()));
+ SchemaField::MakeOptional(1001, "dropped_bucket", int32()));
EXPECT_EQ(partition_type->fields()[2],
SchemaField::MakeOptional(1002, "ts_day", date()));
+ EXPECT_EQ(partition_type->fields()[3],
+ SchemaField::MakeOptional(1003, "dropped_day", date()));
+ EXPECT_EQ(partition_type->fields()[4],
+ SchemaField::MakeOptional(1004, "dropped_year", int32()));
}
TEST(PartitionSpecTest, RawPartitionTypeNoReassign) {