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

zhjwpku 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 83a61351 fix: wrong serialization for partition spec legacy v1 (#1171)
83a61351 is described below

commit 83a613510b90a993369337eb987bd95114317bd0
Author: Hyeonho Kim <[email protected]>
AuthorDate: Wed Nov 25 16:29:35 2026 +0900

    fix: wrong serialization for partition spec legacy v1 (#1171)
---
 src/iceberg/json_serde.cc               |  2 +-
 src/iceberg/test/metadata_serde_test.cc | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/iceberg/json_serde.cc b/src/iceberg/json_serde.cc
index 16f86d19..2b762c06 100644
--- a/src/iceberg/json_serde.cc
+++ b/src/iceberg/json_serde.cc
@@ -1383,7 +1383,7 @@ Result<nlohmann::json> ToJson(const TableMetadata& 
table_metadata) {
   if (table_metadata.format_version == 1) {
     for (const auto& partition_spec : table_metadata.partition_specs) {
       if (partition_spec->spec_id() == table_metadata.default_spec_id) {
-        json[kPartitionSpec] = ToJson(*partition_spec);
+        json[kPartitionSpec] = PartitionFieldsToJson(*partition_spec);
         break;
       }
     }
diff --git a/src/iceberg/test/metadata_serde_test.cc 
b/src/iceberg/test/metadata_serde_test.cc
index ed54ae29..3a50b94f 100644
--- a/src/iceberg/test/metadata_serde_test.cc
+++ b/src/iceberg/test/metadata_serde_test.cc
@@ -178,6 +178,20 @@ TEST(MetadataSerdeTest, DeserializeV1Valid) {
   ASSERT_FALSE(metadata->Snapshot().has_value());
 }
 
+TEST(MetadataSerdeTest, SerializeV1LegacyPartitionSpecAsFields) {
+  ICEBERG_UNWRAP_OR_FAIL(auto metadata,
+                         
ReadTableMetadataFromResource("TableMetadataV1Valid.json"));
+  ICEBERG_UNWRAP_OR_FAIL(auto expected_spec, metadata->PartitionSpec());
+  ICEBERG_UNWRAP_OR_FAIL(auto json, ToJson(*metadata));
+
+  ASSERT_TRUE(json.contains("partition-spec"));
+  EXPECT_TRUE(json.at("partition-spec").is_array());
+
+  json.erase("partition-specs");
+  ICEBERG_UNWRAP_OR_FAIL(auto reparsed, TableMetadataFromJson(json));
+  AssertPartitionSpec(*reparsed, *expected_spec);
+}
+
 TEST(MetadataSerdeTest, DeserializeV2Valid) {
   ICEBERG_UNWRAP_OR_FAIL(auto metadata,
                          
ReadTableMetadataFromResource("TableMetadataV2Valid.json"));

Reply via email to