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

Method CombineChunks

cpp/src/arrow/table.cc:599–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597}
598
599Result<std::shared_ptr<Table>> Table::CombineChunks(MemoryPool* pool) const {
600 const int ncolumns = num_columns();
601 std::vector<std::shared_ptr<ChunkedArray>> compacted_columns(ncolumns);
602 for (int i = 0; i < ncolumns; ++i) {
603 const auto& col = column(i);
604 if (col->num_chunks() <= 1) {
605 compacted_columns[i] = col;
606 continue;
607 }
608
609 if (is_binary_like(col->type()->id())) {
610 // ARROW-5744 Allow binary columns to be combined into multiple chunks to avoid
611 // buffer overflow
612 ArrayVector chunks;
613 int chunk_i = 0;
614 while (chunk_i < col->num_chunks()) {
615 ArrayVector safe_chunks;
616 int64_t data_length = 0;
617 for (; chunk_i < col->num_chunks(); ++chunk_i) {
618 const auto& chunk = col->chunk(chunk_i);
619 data_length += checked_cast<const BinaryArray&>(*chunk).total_values_length();
620 if (data_length >= kBinaryMemoryLimit) {
621 break;
622 }
623 safe_chunks.push_back(chunk);
624 }
625 chunks.emplace_back();
626 ARROW_ASSIGN_OR_RAISE(chunks.back(), Concatenate(safe_chunks, pool));
627 }
628 compacted_columns[i] = std::make_shared<ChunkedArray>(std::move(chunks));
629 } else {
630 ARROW_ASSIGN_OR_RAISE(auto compacted, Concatenate(col->chunks(), pool));
631 compacted_columns[i] = std::make_shared<ChunkedArray>(compacted);
632 }
633 }
634 return Table::Make(schema(), std::move(compacted_columns), num_rows_);
635}
636
637Result<std::shared_ptr<RecordBatch>> Table::CombineChunksToBatch(MemoryPool* pool) const {
638 ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Table> combined, CombineChunks(pool));

Callers 10

FinalizeMethod · 0.80
ReadAsBatchMethod · 0.80
SetUpMethod · 0.80
CheckRoundTripResultFunction · 0.80
CheckBatchesLogicalMethod · 0.80
TEST_FFunction · 0.80
ConcatAndCombineFunction · 0.80

Calls 13

is_binary_likeFunction · 0.85
ConcatenateFunction · 0.85
total_values_lengthMethod · 0.80
push_backMethod · 0.80
emplace_backMethod · 0.80
backMethod · 0.80
num_columnsFunction · 0.70
MakeFunction · 0.70
schemaFunction · 0.70
ARROW_ASSIGN_OR_RAISEFunction · 0.50
num_chunksMethod · 0.45
idMethod · 0.45

Tested by 8

ReadAsBatchMethod · 0.64
SetUpMethod · 0.64
CheckRoundTripResultFunction · 0.64
CheckBatchesLogicalMethod · 0.64
TEST_FFunction · 0.64
ConcatAndCombineFunction · 0.64