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

Method FirstBlock

cpp/src/arrow/json/reader.cc:471–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469
470 private:
471 static Future<DecodedBlock> FirstBlock(AsyncGenerator<DecodedBlock> gen) {
472 // Read from the stream until we get a non-empty record batch that we can use to
473 // declare the schema. Along the way, accumulate the bytes read so they can be
474 // recorded on the first `ReadNextAsync`
475 auto loop_body =
476 [gen = std::move(gen),
477 out = std::make_shared<DecodedBlock>()]() -> Future<ControlFlow<DecodedBlock>> {
478 return gen().Then(
479 [out](const DecodedBlock& block) -> Result<ControlFlow<DecodedBlock>> {
480 if (IsIterationEnd(block)) {
481 return Status::Invalid("Empty JSON stream");
482 }
483 out->num_bytes += block.num_bytes;
484 if (block.record_batch->num_rows() == 0) {
485 return Continue();
486 }
487 out->record_batch = block.record_batch;
488 return Break(*out);
489 });
490 };
491 return Loop(std::move(loop_body));
492 }
493
494 std::optional<DecodedBlock> first_block_;
495 std::shared_ptr<Schema> schema_;

Callers

nothing calls this directly

Calls 8

IsIterationEndFunction · 0.85
ContinueClass · 0.85
BreakFunction · 0.85
LoopFunction · 0.85
ThenMethod · 0.80
genFunction · 0.50
InvalidFunction · 0.50
num_rowsMethod · 0.45

Tested by

no test coverage detected