diff --git a/cpp/src/arrow/flight/types.cc b/cpp/src/arrow/flight/types.cc index efc96bb7756..ddb8a036fbc 100644 --- a/cpp/src/arrow/flight/types.cc +++ b/cpp/src/arrow/flight/types.cc @@ -150,6 +150,12 @@ arrow::Result> SchemaResult::GetSchema( return ipc::ReadSchema(&schema_reader, dictionary_memo); } +arrow::Result SchemaResult::Make(const Schema& schema) { + std::string schema_in; + RETURN_NOT_OK(internal::SchemaToString(schema, &schema_in)); + return SchemaResult(std::move(schema_in)); +} + Status SchemaResult::GetSchema(ipc::DictionaryMemo* dictionary_memo, std::shared_ptr* out) const { return GetSchema(dictionary_memo).Value(out); diff --git a/cpp/src/arrow/flight/types.h b/cpp/src/arrow/flight/types.h index 8a77b8fc0c1..a061f33afec 100644 --- a/cpp/src/arrow/flight/types.h +++ b/cpp/src/arrow/flight/types.h @@ -396,6 +396,9 @@ struct ARROW_FLIGHT_EXPORT SchemaResult { public: explicit SchemaResult(std::string schema) : raw_schema_(std::move(schema)) {} + /// \brief Factory method to construct a SchemaResult. + static arrow::Result Make(const Schema& schema); + /// \brief return schema /// \param[in,out] dictionary_memo for dictionary bookkeeping, will /// be modified diff --git a/cpp/src/arrow/python/flight.cc b/cpp/src/arrow/python/flight.cc index 51155e53833..9077bbe4acb 100644 --- a/cpp/src/arrow/python/flight.cc +++ b/cpp/src/arrow/python/flight.cc @@ -18,7 +18,6 @@ #include #include -#include "arrow/flight/serialization_internal.h" #include "arrow/python/flight.h" #include "arrow/util/io_util.h" #include "arrow/util/logging.h" @@ -371,24 +370,19 @@ Status CreateFlightInfo(const std::shared_ptr& schema, const std::vector& endpoints, int64_t total_records, int64_t total_bytes, std::unique_ptr* out) { - arrow::flight::FlightInfo::Data flight_data; - RETURN_NOT_OK(arrow::flight::internal::SchemaToString(*schema, &flight_data.schema)); - flight_data.descriptor = descriptor; - flight_data.endpoints = endpoints; - flight_data.total_records = total_records; - flight_data.total_bytes = total_bytes; - arrow::flight::FlightInfo value(flight_data); - *out = std::unique_ptr(new arrow::flight::FlightInfo(value)); + ARROW_ASSIGN_OR_RAISE(auto result, + arrow::flight::FlightInfo::Make(*schema, descriptor, endpoints, + total_records, total_bytes)); + *out = std::unique_ptr( + new arrow::flight::FlightInfo(std::move(result))); return Status::OK(); } Status CreateSchemaResult(const std::shared_ptr& schema, std::unique_ptr* out) { - std::string schema_in; - RETURN_NOT_OK(arrow::flight::internal::SchemaToString(*schema, &schema_in)); - arrow::flight::SchemaResult value(schema_in); + ARROW_ASSIGN_OR_RAISE(auto result, arrow::flight::SchemaResult::Make(*schema)); *out = std::unique_ptr( - new arrow::flight::SchemaResult(value)); + new arrow::flight::SchemaResult(std::move(result))); return Status::OK(); }