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 7c05bb3a fix: write decimal types in the spec's canonical "decimal(P, 
S)" form (#1146)
7c05bb3a is described below

commit 7c05bb3af55210fb7237c17668fe0bcb9494f8a1
Author: wzhuo <[email protected]>
AuthorDate: Wed Nov 25 17:57:15 2026 +0800

    fix: write decimal types in the spec's canonical "decimal(P, S)" form 
(#1146)
    
    Appendix C of the spec serializes a decimal type as "decimal(<P>, <S>)",
    with "decimal(9, 2)" as its example, since apache/iceberg#18145. ToJson
    wrote "decimal(9,2)". DecimalType::ToString and Java already write the
    spaced form.
    
    TypeFromJson accepts both spellings, so existing metadata still reads.
    
    Closes #1142.
---
 src/iceberg/json_serde.cc            |  2 +-
 src/iceberg/test/schema_json_test.cc | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/iceberg/json_serde.cc b/src/iceberg/json_serde.cc
index 2b762c06..13259f10 100644
--- a/src/iceberg/json_serde.cc
+++ b/src/iceberg/json_serde.cc
@@ -663,7 +663,7 @@ Result<nlohmann::json> ToJson(const Type& type) {
       return "double";
     case TypeId::kDecimal: {
       const auto& decimal_type = internal::checked_cast<const 
DecimalType&>(type);
-      return std::format("decimal({},{})", decimal_type.precision(),
+      return std::format("decimal({}, {})", decimal_type.precision(),
                          decimal_type.scale());
     }
     case TypeId::kDate:
diff --git a/src/iceberg/test/schema_json_test.cc 
b/src/iceberg/test/schema_json_test.cc
index 5067191b..48fce03b 100644
--- a/src/iceberg/test/schema_json_test.cc
+++ b/src/iceberg/test/schema_json_test.cc
@@ -78,7 +78,7 @@ INSTANTIATE_TEST_SUITE_P(
         SchemaJsonParam{.json = "\"geography(srid:4326, karney)\"",
                         .type = iceberg::geography("srid:4326", 
EdgeAlgorithm::kKarney)},
         SchemaJsonParam{.json = "\"fixed[8]\"", .type = iceberg::fixed(8)},
-        SchemaJsonParam{.json = "\"decimal(10,2)\"", .type = 
iceberg::decimal(10, 2)},
+        SchemaJsonParam{.json = "\"decimal(10, 2)\"", .type = 
iceberg::decimal(10, 2)},
         SchemaJsonParam{.json = "\"date\"", .type = iceberg::date()},
         SchemaJsonParam{.json = "\"time\"", .type = iceberg::time()},
         SchemaJsonParam{.json = "\"timestamp\"", .type = iceberg::timestamp()},
@@ -121,6 +121,14 @@ TEST(TypeJsonTest, FromJsonWithSpaces) {
   ASSERT_NE(decimal, nullptr);
   ASSERT_EQ(decimal->precision(), 10);
   ASSERT_EQ(decimal->scale(), 2);
+  ICEBERG_UNWRAP_OR_FAIL(auto decimal_written, ToJson(*decimal));
+  ASSERT_EQ(decimal_written, "decimal(10, 2)");
+
+  ICEBERG_UNWRAP_OR_FAIL(auto no_space,
+                         
TypeFromJson(nlohmann::json::parse("\"decimal(10,2)\"")));
+  ASSERT_EQ(*no_space, *iceberg::decimal(10, 2));
+  ICEBERG_UNWRAP_OR_FAIL(auto no_space_written, ToJson(*no_space));
+  ASSERT_EQ(no_space_written, "decimal(10, 2)");
 }
 
 TEST(TypeJsonTest, FromJsonV3TypesWithSpacesAndCase) {

Reply via email to