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

Method ReadAsync

cpp/src/arrow/csv/reader.cc:1058–1094  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1056 Result<std::shared_ptr<Table>> Read() override { return ReadAsync().result(); }
1057
1058 Future<std::shared_ptr<Table>> ReadAsync() override {
1059 // Note that this task group doesn't survive our destruction, so it's essential
1060 // that async callbacks own a strong ref to us.
1061 task_group_ = TaskGroup::MakeThreaded(cpu_executor_, io_context_.stop_token());
1062
1063 auto self = shared_from_this();
1064 return ProcessFirstBuffer().Then([self](const std::shared_ptr<Buffer>& first_buffer) {
1065 auto block_generator = ThreadedBlockReader::MakeAsyncIterator(
1066 self->buffer_generator_, MakeChunker(self->parse_options_), first_buffer,
1067 self->read_options_.skip_rows_after_names);
1068
1069 std::function<Status(CSVBlock)> block_visitor =
1070 [self](CSVBlock maybe_block) -> Status {
1071 // The logic in VisitAsyncGenerator ensures that we will never be
1072 // passed an empty block (visit does not call with the end token) so
1073 // we can be assured maybe_block has a value.
1074 DCHECK_GE(maybe_block.block_index, 0);
1075 DCHECK(!maybe_block.consume_bytes);
1076
1077 // Launch parse task
1078 self->task_group_->Append(
1079 [self, maybe_block] { return self->ParseAndInsert(maybe_block); });
1080 return Status::OK();
1081 };
1082
1083 return VisitAsyncGenerator(std::move(block_generator), block_visitor)
1084 .Then([self]() -> Future<> {
1085 // By this point we've added all top level tasks so it is safe to call
1086 // FinishAsync
1087 return self->task_group_->FinishAsync();
1088 })
1089 .Then([self]() -> Result<std::shared_ptr<Table>> {
1090 // Finish conversion, create schema and table
1091 return self->MakeTable();
1092 });
1093 });
1094 }
1095
1096 protected:
1097 Future<std::shared_ptr<Buffer>> ProcessFirstBuffer() {

Callers

nothing calls this directly

Calls 8

VisitAsyncGeneratorFunction · 0.85
ThenMethod · 0.80
MakeTableMethod · 0.80
MakeChunkerFunction · 0.70
OKFunction · 0.50
AppendMethod · 0.45
ParseAndInsertMethod · 0.45
FinishAsyncMethod · 0.45

Tested by

no test coverage detected