From 1d5ab9ef495898447b20449a0059b5e8a1a6c0b9 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 8 Jul 2022 10:40:32 +0200 Subject: [PATCH 1/3] Remove the need for serialization_internal.h inside python/flight.cc --- cpp/src/arrow/flight/types.cc | 6 ++++++ cpp/src/arrow/flight/types.h | 3 +++ cpp/src/arrow/python/flight.cc | 23 ++++++++++------------- 3 files changed, 19 insertions(+), 13 deletions(-) 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..e0a4236e9f6 100644 --- a/cpp/src/arrow/python/flight.cc +++ b/cpp/src/arrow/python/flight.cc @@ -371,24 +371,21 @@ 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); - *out = std::unique_ptr( - new arrow::flight::SchemaResult(value)); + ARROW_ASSIGN_OR_RAISE(auto result, + arrow::flight::SchemaResult::Make(*schema)); + *out = std::unique_ptr(new arrow::flight::SchemaResult(std::move(result))); return Status::OK(); } From 0a8305b147a66325f0a7d477ed7205bb41593b0d Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 8 Jul 2022 11:01:26 +0200 Subject: [PATCH 2/3] Remove internal headers from flight.cc --- cpp/src/arrow/python/flight.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/src/arrow/python/flight.cc b/cpp/src/arrow/python/flight.cc index e0a4236e9f6..6580abe511b 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" From b37aaaf5fbaab2af9c4ee1ae51805f3eb852f781 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 8 Jul 2022 13:33:04 +0200 Subject: [PATCH 3/3] Linter errors --- cpp/src/arrow/python/flight.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cpp/src/arrow/python/flight.cc b/cpp/src/arrow/python/flight.cc index 6580abe511b..9077bbe4acb 100644 --- a/cpp/src/arrow/python/flight.cc +++ b/cpp/src/arrow/python/flight.cc @@ -371,20 +371,18 @@ Status CreateFlightInfo(const std::shared_ptr& schema, int64_t total_records, int64_t total_bytes, std::unique_ptr* out) { 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))); + 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) { - ARROW_ASSIGN_OR_RAISE(auto result, - arrow::flight::SchemaResult::Make(*schema)); - *out = std::unique_ptr(new arrow::flight::SchemaResult(std::move(result))); + ARROW_ASSIGN_OR_RAISE(auto result, arrow::flight::SchemaResult::Make(*schema)); + *out = std::unique_ptr( + new arrow::flight::SchemaResult(std::move(result))); return Status::OK(); }