Skip to content

Commit

Permalink
Merge pull request #1822 from kuzudb/resize-fix
Browse files Browse the repository at this point in the history
Fix struct datavector resizing
  • Loading branch information
acquamarin committed Jul 17, 2023
2 parents 01da5ef + bc11927 commit f6159a4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/common/vector/auxiliary_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ list_entry_t ListAuxiliaryBuffer::addList(uint64_t listSize) {
}

void ListAuxiliaryBuffer::resizeDataVector(ValueVector* dataVector) {
auto buffer = std::make_unique<uint8_t[]>(capacity * dataVector->getNumBytesPerValue());
memcpy(buffer.get(), dataVector->valueBuffer.get(), size * dataVector->getNumBytesPerValue());
dataVector->valueBuffer = std::move(buffer);
dataVector->nullMask->resize(capacity);
// If the dataVector is a struct vector, we need to resize its field vectors.
if (dataVector->dataType.getPhysicalType() == PhysicalTypeID::STRUCT) {
auto fieldVectors = StructVector::getFieldVectors(dataVector);
for (auto& fieldVector : fieldVectors) {
resizeDataVector(fieldVector.get());
}
} else {
auto buffer = std::make_unique<uint8_t[]>(capacity * dataVector->getNumBytesPerValue());
memcpy(
buffer.get(), dataVector->valueBuffer.get(), size * dataVector->getNumBytesPerValue());
dataVector->valueBuffer = std::move(buffer);
dataVector->nullMask->resize(capacity);
resizeStructDataVector(dataVector);
}
}

void ListAuxiliaryBuffer::resizeStructDataVector(ValueVector* dataVector) {
std::iota(reinterpret_cast<int64_t*>(
dataVector->getData() + dataVector->getNumBytesPerValue() * size),
reinterpret_cast<int64_t*>(
dataVector->getData() + dataVector->getNumBytesPerValue() * capacity),
size);
auto fieldVectors = StructVector::getFieldVectors(dataVector);
for (auto& fieldVector : fieldVectors) {
resizeDataVector(fieldVector.get());
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/common/vector/auxiliary_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class ListAuxiliaryBuffer : public AuxiliaryBuffer {
private:
void resizeDataVector(ValueVector* dataVector);

void resizeStructDataVector(ValueVector* dataVector);

private:
uint64_t capacity;
uint64_t size;
Expand Down
Loading

0 comments on commit f6159a4

Please sign in to comment.