MCPcopy Create free account
hub / github.com/bytedance/bolt / flush

Method flush

bolt/serializers/ArrowSerializer.cpp:537–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

535 }
536
537 void flush(OutputStream* stream) override {
538 ::arrow::ipc::IpcWriteOptions wopts =
539 ::arrow::ipc::IpcWriteOptions::Defaults();
540 wopts.metadata_version = ::arrow::ipc::MetadataVersion::V4;
541
542 // schema
543 std::shared_ptr<::arrow::Schema> schema;
544 if (!batches_.empty()) {
545 schema = batches_.front()->schema();
546 } else {
547 ArrowSchema cSchema{};
548 ArrowSchemaReleaser schemaRel(&cSchema);
549 auto* pool = streamArena_->pool();
550 auto empty = BaseVector::create<RowVector>(rowType_, 0, pool);
551 exportToArrow(empty, cSchema, arrowBridgeOptions_, {});
552 auto schRes = ::arrow::ImportSchema(&cSchema);
553 BOLT_USER_CHECK(
554 schRes.ok(),
555 "ImportSchema(empty) failed: {}",
556 schRes.status().ToString());
557 schema = *schRes;
558 schemaRel.disarm();
559 }
560
561#ifndef NDEBUG
562 for (size_t i = 0; i < batches_.size(); ++i) {
563 BOLT_CHECK(
564 batches_[i]->schema()->Equals(*schema),
565 "Schema mismatch at batch {}:\nexpected: {}\n found: {}",
566 i,
567 schema->ToString(),
568 batches_[i]->schema()->ToString());
569 }
570#endif
571
572 const int32_t rowsToWrite = totalRows_;
573
574 // header = rows | codec | uncompressed size | compressed size | checksum
575 writeInt32(stream, rowsToWrite);
576 const std::streampos codec_pos = stream->tellp();
577 const char codecMask = 0;
578
579 auto writeCodec = [&](char codecMask,
580 int32_t uncompressedSize,
581 int32_t compressedSize,
582 bool first = false) {
583 auto pos = stream->tellp();
584 stream->seekp(codec_pos);
585 stream->write(&codecMask, 1);
586 writeInt32(stream, uncompressedSize);
587 writeInt32(stream, compressedSize);
588#ifdef BOLT_ENABLE_CRC
589 writeInt64(stream, 0);
590#endif
591 if (!first) {
592 stream->seekp(pos);
593 VLOG(1) << "[Flush] wrote codec header: "
594 << " rows=" << rowsToWrite

Callers 1

serializeMethod · 0.45

Calls 15

statusMethod · 0.80
WriteRecordBatchMethod · 0.80
writeInt32Function · 0.70
writeInt64Function · 0.70
exportToArrowFunction · 0.50
maxFunction · 0.50
emptyMethod · 0.45
schemaMethod · 0.45
poolMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45
disarmMethod · 0.45

Tested by

no test coverage detected