raulcd commented on code in PR #47410:
URL: https://github.com/apache/arrow/pull/47410#discussion_r2298191512
##########
cpp/src/arrow/flight/transport_server.cc:
##########
@@ -160,25 +161,63 @@ class TransportMessageReader final : public
FlightMessageReader {
std::shared_ptr<Buffer> app_metadata_;
};
-// TODO(ARROW-10787): this should use the same writer/ipc trick as client
+/// \brief An IpcPayloadWriter for ServerDataStream.
+///
+/// To support app_metadata and reuse the existing IPC infrastructure,
+/// this takes a pointer to a buffer to be combined with the IPC
+/// payload when writing a Flight payload.
+class TransportMessagePayloadWriter : public ipc::internal::IpcPayloadWriter {
+ public:
+ TransportMessagePayloadWriter(ServerDataStream* stream,
+ std::shared_ptr<Buffer>* app_metadata)
+ : stream_(stream), app_metadata_(app_metadata) {}
+
+ Status Start() override { return Status::OK(); }
+ Status WritePayload(const ipc::IpcPayload& ipc_payload) override {
+ FlightPayload payload;
+ payload.ipc_message = ipc_payload;
+
+ if (ipc_payload.type == ipc::MessageType::RECORD_BATCH && *app_metadata_) {
+ payload.app_metadata = std::move(*app_metadata_);
+ }
+ ARROW_ASSIGN_OR_RAISE(auto success, stream_->WriteData(payload));
+ if (!success) {
+ return arrow::Status(arrow::StatusCode::IOError,
+ "Could not write record batch to stream");
+ }
+ return arrow::Status::OK();
+ }
+ Status Close() override {
+ // Closing is handled one layer up in TransportMessageWriter::Close
+ return Status::OK();
+ }
+
+ private:
+ ServerDataStream* stream_;
+ std::shared_ptr<Buffer>* app_metadata_;
+};
+
class TransportMessageWriter final : public FlightMessageWriter {
public:
explicit TransportMessageWriter(ServerDataStream* stream)
- : stream_(stream),
ipc_options_(::arrow::ipc::IpcWriteOptions::Defaults()) {}
+ : stream_(stream),
+ app_metadata_(nullptr),
+ ipc_options_(::arrow::ipc::IpcWriteOptions::Defaults()) {}
Status Begin(const std::shared_ptr<Schema>& schema,
const ipc::IpcWriteOptions& options) override {
- if (started_) {
+ ipc_options_ = options;
+ if (batch_writer_) {
Review Comment:
I should have removed `started_` from `CheckStarted` and just use the
`batch_writer_` as we do on the client. I've updated `CheckStarted` accordingly
and remove the now unnecessary `started_` flag.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]