@@ -206,6 +206,19 @@ Result<std::unique_ptr<SortField>> SortFieldFromJson(const nlohmann::json& json)
206206 null_order);
207207}
208208
209+ Result<std::unique_ptr<SortOrder>> SortOrderFromJson (
210+ const nlohmann::json& json, const std::shared_ptr<Schema>& current_schema) {
211+ ICEBERG_ASSIGN_OR_RAISE (auto order_id, GetJsonValue<int32_t >(json, kOrderId ));
212+ ICEBERG_ASSIGN_OR_RAISE (auto fields, GetJsonValue<nlohmann::json>(json, kFields ));
213+
214+ std::vector<SortField> sort_fields;
215+ for (const auto & field_json : fields) {
216+ ICEBERG_ASSIGN_OR_RAISE (auto sort_field, SortFieldFromJson (field_json));
217+ sort_fields.push_back (std::move (*sort_field));
218+ }
219+ return SortOrder::Make (*current_schema, order_id, std::move (sort_fields));
220+ }
221+
209222Result<std::unique_ptr<SortOrder>> SortOrderFromJson (const nlohmann::json& json) {
210223 ICEBERG_ASSIGN_OR_RAISE (auto order_id, GetJsonValue<int32_t >(json, kOrderId ));
211224 ICEBERG_ASSIGN_OR_RAISE (auto fields, GetJsonValue<nlohmann::json>(json, kFields ));
@@ -215,7 +228,7 @@ Result<std::unique_ptr<SortOrder>> SortOrderFromJson(const nlohmann::json& json)
215228 ICEBERG_ASSIGN_OR_RAISE (auto sort_field, SortFieldFromJson (field_json));
216229 sort_fields.push_back (std::move (*sort_field));
217230 }
218- return std::make_unique<SortOrder> (order_id, std::move (sort_fields));
231+ return SortOrder::Make (order_id, std::move (sort_fields));
219232}
220233
221234nlohmann::json ToJson (const SchemaField& field) {
@@ -919,9 +932,11 @@ Status ParsePartitionSpecs(const nlohmann::json& json, int8_t format_version,
919932// /
920933// / \param[in] json The JSON object to parse.
921934// / \param[in] format_version The format version of the table.
935+ // / \param[in] current_schema The current schema.
922936// / \param[out] default_sort_order_id The default sort order ID.
923937// / \param[out] sort_orders The list of sort orders.
924938Status ParseSortOrders (const nlohmann::json& json, int8_t format_version,
939+ const std::shared_ptr<Schema>& current_schema,
925940 int32_t & default_sort_order_id,
926941 std::vector<std::shared_ptr<SortOrder>>& sort_orders) {
927942 if (json.contains (kSortOrders )) {
@@ -930,7 +945,8 @@ Status ParseSortOrders(const nlohmann::json& json, int8_t format_version,
930945 ICEBERG_ASSIGN_OR_RAISE (auto sort_order_array,
931946 GetJsonValue<nlohmann::json>(json, kSortOrders ));
932947 for (const auto & sort_order_json : sort_order_array) {
933- ICEBERG_ASSIGN_OR_RAISE (auto sort_order, SortOrderFromJson (sort_order_json));
948+ ICEBERG_ASSIGN_OR_RAISE (auto sort_order,
949+ SortOrderFromJson (sort_order_json, current_schema));
934950 sort_orders.push_back (std::move (sort_order));
935951 }
936952 } else {
@@ -1005,9 +1021,9 @@ Result<std::unique_ptr<TableMetadata>> TableMetadataFromJson(const nlohmann::jso
10051021 }
10061022 }
10071023
1008- ICEBERG_RETURN_UNEXPECTED (ParseSortOrders (json, table_metadata-> format_version ,
1009- table_metadata->default_sort_order_id ,
1010- table_metadata->sort_orders ));
1024+ ICEBERG_RETURN_UNEXPECTED (ParseSortOrders (
1025+ json, table_metadata->format_version , current_schema ,
1026+ table_metadata-> default_sort_order_id , table_metadata->sort_orders ));
10111027
10121028 if (json.contains (kProperties )) {
10131029 ICEBERG_ASSIGN_OR_RAISE (table_metadata->properties , FromJsonMap (json, kProperties ));
0 commit comments