@@ -668,13 +668,12 @@ nlohmann::json ToJson(const PartitionSpec& partition_spec) {
668668}
669669
670670Result<std::unique_ptr<PartitionField>> PartitionFieldFromJson (
671- const nlohmann::json& json, bool allow_field_id_missing ) {
671+ const nlohmann::json& json, std::optional< int32_t > partition_field_id ) {
672672 ICEBERG_ASSIGN_OR_RAISE (auto source_id, GetJsonValue<int32_t >(json, kSourceId ));
673673 int32_t field_id;
674- if (allow_field_id_missing) {
675- // Partition field id in v1 is not tracked, so we use -1 to indicate that.
676- ICEBERG_ASSIGN_OR_RAISE (field_id, GetJsonValueOrDefault<int32_t >(
677- json, kFieldId , SchemaField::kInvalidFieldId ));
674+ if (partition_field_id.has_value ()) {
675+ // Partition field id in v1 is not tracked, so we use partition_field_id directly.
676+ field_id = partition_field_id.value ();
678677 } else {
679678 ICEBERG_ASSIGN_OR_RAISE (field_id, GetJsonValue<int32_t >(json, kFieldId ));
680679 }
@@ -1053,14 +1052,10 @@ Status ParsePartitionSpecs(const nlohmann::json& json, int8_t format_version,
10531052 int32_t next_partition_field_id = PartitionSpec::kLegacyPartitionDataIdStart ;
10541053 std::vector<PartitionField> fields;
10551054 for (const auto & entry_json : partition_spec_json) {
1056- ICEBERG_ASSIGN_OR_RAISE (auto field, PartitionFieldFromJson (entry_json, true ));
1057- int32_t field_id = field->field_id ();
1058- if (field_id == SchemaField::kInvalidFieldId ) {
1059- // If the field ID is not set, we need to assign a new one
1060- field_id = next_partition_field_id++;
1061- }
1062- fields.emplace_back (field->source_id (), field_id, std::string (field->name ()),
1063- std::move (field->transform ()));
1055+ ICEBERG_ASSIGN_OR_RAISE (
1056+ auto field, PartitionFieldFromJson (entry_json, next_partition_field_id));
1057+ next_partition_field_id++;
1058+ fields.push_back (std::move (*field));
10641059 }
10651060
10661061 auto spec = std::make_unique<PartitionSpec>(
0 commit comments