Skip to content

Commit

Permalink
add reserve and assert recordbatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Light-City committed Oct 13, 2023
1 parent 35a414a commit 5996810
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/record_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,10 @@ Result<std::shared_ptr<RecordBatch>> ConcatenateRecordBatches(
}

std::vector<std::shared_ptr<Array>> concatenated_columns;
concatenated_columns.reserve(cols);
for (int col = 0; col < cols; ++col) {
ArrayVector column_arrays;
column_arrays.reserve(batches.size());
for (const auto& batch : batches) {
column_arrays.emplace_back(batch->column(col));
}
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/arrow/record_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ class ARROW_EXPORT RecordBatchReader {

/// \brief Concatenate record batches
///
/// The columns of the new batch are formed by concatenate the same columns of each input
/// batch. Concatenate multiple batches into a new batch requires that the schema must be
/// consistent. It supports merging batches without columns (only length, scenarios such
/// as count(*)).
///
/// \param[in] batches a vector of record batches to be concatenated
/// \param[in] pool memory to store the result will be allocated from this memory pool
/// \return the concatenated record batch
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/record_batch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ TEST_F(TestRecordBatch, ConcatenateRecordBatches) {

ASSERT_OK_AND_ASSIGN(auto batch, ConcatenateRecordBatches({b1, b2}));
ASSERT_EQ(batch->num_rows(), b1->num_rows() + b2->num_rows());
ASSERT_BATCHES_EQUAL(*batch->Slice(0, b1->num_rows()), *b1);
ASSERT_BATCHES_EQUAL(*batch->Slice(b1->num_rows()), *b2);

f0 = field("fd0", int32());
f1 = field("fd1", uint8());
Expand All @@ -587,6 +589,7 @@ TEST_F(TestRecordBatch, ConcatenateRecordBatches) {
std::vector<std::shared_ptr<ArrayData>>{});
ASSERT_OK_AND_ASSIGN(batch, ConcatenateRecordBatches({null_batch}));
ASSERT_EQ(batch->num_rows(), null_batch->num_rows());
ASSERT_BATCHES_EQUAL(*batch, *null_batch);
}

} // namespace arrow

0 comments on commit 5996810

Please sign in to comment.