MCPcopy Create free account
hub / github.com/apache/arrow / RunExchangeTotal

Method RunExchangeTotal

cpp/src/arrow/flight/test_flight_server.cc:260–311  ·  view source on GitHub ↗

Read int64 batches from the client, each time sending back a batch with a running sum of columns.

Source from the content-addressed store, hash-verified

258// Read int64 batches from the client, each time sending back a
259// batch with a running sum of columns.
260Status TestFlightServer::RunExchangeTotal(std::unique_ptr<FlightMessageReader> reader,
261 std::unique_ptr<FlightMessageWriter> writer) {
262 FlightStreamChunk chunk{};
263 ARROW_ASSIGN_OR_RAISE(auto schema, reader->GetSchema());
264 // Ensure the schema contains only int64 columns
265 for (const auto& field : schema->fields()) {
266 if (field->type()->id() != Type::type::INT64) {
267 return Status::Invalid("Field is not INT64: ", field->name());
268 }
269 }
270 std::vector<int64_t> sums(schema->num_fields());
271 std::vector<std::shared_ptr<Array>> columns(schema->num_fields());
272 RETURN_NOT_OK(writer->Begin(schema));
273 while (true) {
274 ARROW_ASSIGN_OR_RAISE(chunk, reader->Next());
275 if (!chunk.data && !chunk.app_metadata) {
276 break;
277 }
278 if (chunk.data) {
279 if (!chunk.data->schema()->Equals(schema, false)) {
280 // A compliant client implementation would make this impossible
281 return Status::Invalid("Schemas are incompatible");
282 }
283
284 // Update the running totals
285 auto builder = std::make_shared<Int64Builder>();
286 int col_index = 0;
287 for (const auto& column : chunk.data->columns()) {
288 auto arr = std::dynamic_pointer_cast<Int64Array>(column);
289 if (!arr) {
290 return MakeFlightError(FlightStatusCode::Internal, "Could not cast array");
291 }
292 for (int row = 0; row < column->length(); row++) {
293 if (!arr->IsNull(row)) {
294 sums[col_index] += arr->Value(row);
295 }
296 }
297
298 builder->Reset();
299 RETURN_NOT_OK(builder->Append(sums[col_index]));
300 RETURN_NOT_OK(builder->Finish(&columns[col_index]));
301
302 col_index++;
303 }
304
305 // Echo the totals to the client
306 auto response = RecordBatch::Make(schema, /* num_rows */ 1, columns);
307 RETURN_NOT_OK(writer->WriteRecordBatch(*response));
308 }
309 }
310 return Status::OK();
311}
312
313// Echo the client's messages back.
314Status TestFlightServer::RunExchangeEcho(std::unique_ptr<FlightMessageReader> reader,

Callers

nothing calls this directly

Calls 15

MakeFlightErrorFunction · 0.85
columnsMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
InvalidFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50
fieldsMethod · 0.45
idMethod · 0.45
typeMethod · 0.45
nameMethod · 0.45
num_fieldsMethod · 0.45
BeginMethod · 0.45

Tested by

no test coverage detected