Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix FlatVector copy memory issue (#11482) #11483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joeg
Copy link

@joeg joeg commented Nov 8, 2024

Summary:

When copy-ing a FlatVector the source memory pool is used. This is a problem when the vector needs to live beyond the lifetime of the source pool.

For strings this requires recomputing new StringViews over newly copied string buffers. This is useful in cases where you need to maintain result rows beyond the lifetime of a given presto task / query.

Reviewed By: arhimondr

Differential Revision: D65306907

Summary:

When copy-ing a FlatVector the source memory pool is used. This is a problem when the vector needs to live beyond the lifetime of the source pool. 

For strings this requires recomputing new StringViews over newly copied string buffers. This is useful in cases where you need to maintain result rows beyond the lifetime of a given presto task / query.

Reviewed By: arhimondr

Differential Revision: D65306907
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 8, 2024
Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 58c233f
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/672e60c025940900070b5a98

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65306907

@@ -274,12 +274,13 @@ class FlatVector final : public SimpleVector<T> {

VectorPtr copyPreserveEncodings(
velox::memory::MemoryPool* pool = nullptr) const override {
auto allocPool = pool ? pool : BaseVector::pool_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto

template <>
VectorPtr FlatVector<StringView>::copyPreserveEncodings(
velox::memory::MemoryPool* pool) const {
auto allocPool = pool ? pool : BaseVector::pool_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto

auto newValuesBuffer =
AlignedBuffer::allocate<StringView>(BaseVector::size(), allocPool);
auto rawCopyValues = newValuesBuffer->asMutable<StringView>();
// Copy non Null StringViews to value buffer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. in the end

}
}

BufferPtr newStringBuffer = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector stringBuffers, and emplace_back to it if have

@jinchengchenghh
Copy link
Contributor

Please remove - in the title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants