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

Method TranslateMinimalBatch

cpp/src/arrow/csv/writer.cc:667–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

665 }
666
667 Status TranslateMinimalBatch(const RecordBatch& batch) {
668 if (batch.num_rows() == 0) {
669 return Status::OK();
670 }
671 offsets_.resize(batch.num_rows());
672 std::fill(offsets_.begin(), offsets_.end(), 0);
673
674 // Calculate relative offsets for each row (excluding delimiters)
675 for (int32_t col = 0; col < static_cast<int32_t>(column_populators_.size()); col++) {
676 RETURN_NOT_OK(
677 column_populators_[col]->UpdateRowLengths(*batch.column(col), offsets_.data()));
678 }
679 // Calculate cumulative offsets for each row (including delimiters).
680 // - before conversion: offsets_[i] = length of i-th row
681 // - after conversion: offsets_[i] = offset to the starting of i-th row buffer
682 // - offsets_[0] = 0
683 // - offsets_[i] = offsets_[i-1] + len(i-1-th row) + len(delimiters)
684 // Delimiters: ',' * (num_columns - 1) + eol
685 const int32_t delimiters_length =
686 static_cast<int32_t>(batch.num_columns() - 1 + options_.eol.size());
687 int64_t last_row_length = offsets_[0] + delimiters_length;
688 offsets_[0] = 0;
689 for (size_t row = 1; row < offsets_.size(); ++row) {
690 const int64_t this_row_length = offsets_[row] + delimiters_length;
691 offsets_[row] = offsets_[row - 1] + last_row_length;
692 last_row_length = this_row_length;
693 }
694 // Resize the target buffer to required size. We assume batch to batch sizes
695 // should be pretty close so don't shrink the buffer to avoid allocation churn.
696 RETURN_NOT_OK(
697 data_buffer_->Resize(offsets_.back() + last_row_length, /*shrink_to_fit=*/false));
698
699 // Use the offsets to populate contents.
700 for (auto& populator : column_populators_) {
701 RETURN_NOT_OK(populator->PopulateRows(
702 reinterpret_cast<char*>(data_buffer_->mutable_data()), offsets_.data()));
703 }
704 DCHECK_EQ(data_buffer_->size(), offsets_.back());
705 return Status::OK();
706 }
707
708 static constexpr int64_t kColumnSizeGuess = 8;
709 io::OutputStream* sink_;

Callers

nothing calls this directly

Calls 14

resizeMethod · 0.80
backMethod · 0.80
OKFunction · 0.50
num_rowsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
UpdateRowLengthsMethod · 0.45
columnMethod · 0.45
dataMethod · 0.45
num_columnsMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected