| 127 | } |
| 128 | |
| 129 | void FactorizedTable::resize(uint64_t numTuples) { |
| 130 | if (numTuples > this->numTuples) { |
| 131 | auto numTuplesToAdd = numTuples - this->numTuples; |
| 132 | auto numBytesPerTuple = tableSchema.getNumBytesPerTuple(); |
| 133 | while (flatTupleBlockCollection->needAllocation(numTuplesToAdd * numBytesPerTuple)) { |
| 134 | auto newBlock = std::make_unique<DataBlock>(memoryManager, flatTupleBlockSize); |
| 135 | flatTupleBlockCollection->append(std::move(newBlock)); |
| 136 | auto numTuplesToAddInBlock = |
| 137 | std::min(static_cast<uint32_t>(numTuplesToAdd), numFlatTuplesPerBlock); |
| 138 | auto block = flatTupleBlockCollection->getLastBlock(); |
| 139 | block->freeSize -= numBytesPerTuple * numTuplesToAddInBlock; |
| 140 | block->numTuples += numTuplesToAddInBlock; |
| 141 | numTuplesToAdd -= numTuplesToAddInBlock; |
| 142 | } |
| 143 | DASSERT(numTuplesToAdd < numFlatTuplesPerBlock); |
| 144 | auto block = flatTupleBlockCollection->getLastBlock(); |
| 145 | block->freeSize -= numBytesPerTuple * numTuplesToAdd; |
| 146 | block->numTuples += numTuplesToAdd; |
| 147 | } else { |
| 148 | auto numTuplesRemaining = numTuples; |
| 149 | DASSERT(flatTupleBlockCollection->getBlocks().size() == 1); |
| 150 | // TODO: It always adds to the end, so this will leave empty blocks in the middle if it's |
| 151 | // reused |
| 152 | for (auto& block : flatTupleBlockCollection->getBlocks()) { |
| 153 | block->numTuples = |
| 154 | std::min(static_cast<uint32_t>(numTuplesRemaining), numFlatTuplesPerBlock); |
| 155 | block->freeSize = |
| 156 | block->getSizedData().size() - block->numTuples * tableSchema.getNumBytesPerTuple(); |
| 157 | numTuplesRemaining -= block->numTuples; |
| 158 | } |
| 159 | DASSERT(numTuplesRemaining == 0); |
| 160 | } |
| 161 | this->numTuples = numTuples; |
| 162 | } |
| 163 | uint8_t* FactorizedTable::appendEmptyTuple() { |
| 164 | auto numBytesPerTuple = tableSchema.getNumBytesPerTuple(); |
| 165 | if (flatTupleBlockCollection->needAllocation(numBytesPerTuple)) { |
no test coverage detected