felipecrv commented on code in PR #43678: URL: https://github.com/apache/arrow/pull/43678#discussion_r1716141049
########## cpp/src/arrow/flight/test_flight_server.cc: ########## @@ -0,0 +1,417 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <memory> + +#include "arrow/flight/test_flight_server.h" + +#include "arrow/array/array_base.h" +#include "arrow/array/array_primitive.h" +#include "arrow/array/builder_primitive.h" +#include "arrow/flight/server.h" +#include "arrow/flight/test_util.h" +#include "arrow/flight/type_fwd.h" +#include "arrow/status.h" + +namespace arrow::flight { +namespace { + +class ErrorRecordBatchReader : public RecordBatchReader { + public: + ErrorRecordBatchReader() : schema_(arrow::schema({})) {} + + std::shared_ptr<Schema> schema() const override { return schema_; } + + Status ReadNext(std::shared_ptr<RecordBatch>* out) override { + *out = nullptr; + return Status::OK(); + } + + Status Close() override { + // This should be propagated over DoGet to the client + return Status::IOError("Expected error"); + } + + private: + std::shared_ptr<Schema> schema_; +}; + +Status GetBatchForFlight(const Ticket& ticket, std::shared_ptr<RecordBatchReader>* out) { + if (ticket.ticket == "ticket-ints-1") { + RecordBatchVector batches; + RETURN_NOT_OK(ExampleIntBatches(&batches)); + ARROW_ASSIGN_OR_RAISE(*out, RecordBatchReader::Make(batches)); + return Status::OK(); + } else if (ticket.ticket == "ticket-floats-1") { + RecordBatchVector batches; + RETURN_NOT_OK(ExampleFloatBatches(&batches)); + ARROW_ASSIGN_OR_RAISE(*out, RecordBatchReader::Make(batches)); + return Status::OK(); + } else if (ticket.ticket == "ticket-dicts-1") { + RecordBatchVector batches; + RETURN_NOT_OK(ExampleDictBatches(&batches)); + ARROW_ASSIGN_OR_RAISE(*out, RecordBatchReader::Make(batches)); + return Status::OK(); + } else if (ticket.ticket == "ticket-large-batch-1") { + RecordBatchVector batches; + RETURN_NOT_OK(ExampleLargeBatches(&batches)); + ARROW_ASSIGN_OR_RAISE(*out, RecordBatchReader::Make(batches)); + return Status::OK(); + } else { + return Status::NotImplemented("no stream implemented for ticket: " + ticket.ticket); + } +} + +} // namespace + +std::unique_ptr<FlightServerBase> TestFlightServer::Make() { + return std::make_unique<TestFlightServer>(); +} Review Comment: It's used quite a lot and is handy to not have to write the longer make_unique invocation. This is replacing the old free function called `ExampleTestServer`. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org