MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / merge

Method merge

src/processor/result/factorized_table.cpp:57–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57void DataBlockCollection::merge(DataBlockCollection& other) {
58 if (blocks.empty()) {
59 append(std::move(other.blocks));
60 return;
61 }
62 // Pop up the old last block first, and then push back blocks from other into the vector.
63 auto oldLastBlock = std::move(blocks.back());
64 blocks.pop_back();
65 append(std::move(other.blocks));
66 // Insert back tuples in the old last block to the new last block.
67 auto newLastBlock = blocks.back().get();
68 auto numTuplesToAppendIntoNewLastBlock =
69 std::min(numTuplesPerBlock - newLastBlock->numTuples, oldLastBlock->numTuples);
70 DataBlock::copyTuples(oldLastBlock.get(), 0, newLastBlock, newLastBlock->numTuples,
71 numTuplesToAppendIntoNewLastBlock, numBytesPerTuple);
72 // If any tuples left in the old last block, shift them to the beginning, and push the old last
73 // block back.
74 auto numTuplesLeftForNewBlock = oldLastBlock->numTuples - numTuplesToAppendIntoNewLastBlock;
75 if (numTuplesLeftForNewBlock > 0) {
76 auto tupleIdxInOldLastBlock = numTuplesToAppendIntoNewLastBlock;
77 oldLastBlock->resetNumTuplesAndFreeSize();
78 DataBlock::copyTuples(oldLastBlock.get(), tupleIdxInOldLastBlock, oldLastBlock.get(), 0,
79 numTuplesLeftForNewBlock, numBytesPerTuple);
80 blocks.push_back(std::move(oldLastBlock));
81 }
82}
83
84FactorizedTable::FactorizedTable(MemoryManager* memoryManager, FactorizedTableSchema tableSchema)
85 : memoryManager{memoryManager}, tableSchema{std::move(tableSchema)}, numTuples{0} {

Callers 1

mergeLocalTablesMethod · 0.45

Calls 6

emptyMethod · 0.45
pop_backMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected