@@ -533,7 +533,8 @@ Result<std::unique_ptr<PartitionField>> PartitionFieldFromJson(
533533}
534534
535535Result<std::unique_ptr<PartitionSpec>> PartitionSpecFromJson (
536- const std::shared_ptr<Schema>& schema, const nlohmann::json& json) {
536+ const std::shared_ptr<Schema>& schema, const nlohmann::json& json,
537+ int32_t default_spec_id) {
537538 ICEBERG_ASSIGN_OR_RAISE (auto spec_id, GetJsonValue<int32_t >(json, kSpecId ));
538539 ICEBERG_ASSIGN_OR_RAISE (auto fields, GetJsonValue<nlohmann::json>(json, kFields ));
539540
@@ -542,9 +543,16 @@ Result<std::unique_ptr<PartitionSpec>> PartitionSpecFromJson(
542543 ICEBERG_ASSIGN_OR_RAISE (auto partition_field, PartitionFieldFromJson (field_json));
543544 partition_fields.push_back (std::move (*partition_field));
544545 }
545- ICEBERG_ASSIGN_OR_RAISE (
546- auto spec, PartitionSpec::Make (*schema, spec_id, std::move (partition_fields),
547- true /* allow_missing_fields*/ ));
546+
547+ std::unique_ptr<PartitionSpec> spec;
548+ if (default_spec_id == spec_id) {
549+ ICEBERG_ASSIGN_OR_RAISE (
550+ spec, PartitionSpec::Make (*schema, spec_id, std::move (partition_fields),
551+ true /* allow_missing_fields*/ ));
552+ } else {
553+ ICEBERG_ASSIGN_OR_RAISE (spec,
554+ PartitionSpec::Make (spec_id, std::move (partition_fields)));
555+ }
548556 return spec;
549557}
550558
@@ -886,8 +894,8 @@ Status ParsePartitionSpecs(const nlohmann::json& json, int8_t format_version,
886894 ICEBERG_ASSIGN_OR_RAISE (default_spec_id, GetJsonValue<int32_t >(json, kDefaultSpecId ));
887895
888896 for (const auto & spec_json : spec_array) {
889- ICEBERG_ASSIGN_OR_RAISE (auto spec,
890- PartitionSpecFromJson (current_schema, spec_json));
897+ ICEBERG_ASSIGN_OR_RAISE (
898+ auto spec, PartitionSpecFromJson (current_schema, spec_json, default_spec_id ));
891899 partition_specs.push_back (std::move (spec));
892900 }
893901 } else {
0 commit comments