Skip to content

Commit d89b6c9

Browse files
xiaoxmengfacebook-github-bot
authored andcommitted
fix: Add BaseVector::reusable() to recursively check vector reusability (facebookincubator#502)
Summary: This change adds a new static method BaseVector::reusable() that recursively checks if a vector and all its nested children are reusable (have use_count == 1). The existing verifyVectorState() check in nimble FieldReader only verified the top-level vector's use_count, but complex types like ARRAY<ROW<BIGINT, REAL>> can have nested children that are shared across different parent vectors. When prepareForReuse() is called on a vector whose nested children are still referenced elsewhere, it corrupts those shared children by resetting them to size 0. Adds BaseVector::reusable() which recursively checks use_count for ROW children, ARRAY elements, and MAP keys/values Updates verifyVectorState() in nimble FieldReader to use the new recursive check Adds unit tests for the new method Differential Revision: D93790972
1 parent 0263aea commit d89b6c9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

dwio/nimble/velox/FieldReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ void zeroNulls(velox::BaseVector* vector, uint32_t rowCount) {
5757

5858
template <typename T>
5959
T* verifyVectorState(velox::VectorPtr& vector) {
60-
// we want vector to not be referenced by anyone else (e.g. ref count of 1)
60+
// we want vector AND all its nested children to not be referenced by anyone
61+
// else (e.g. ref count of 1 recursively). Use BaseVector::reusable
62+
// from Velox to check this.
6163
if (vector != nullptr) {
6264
auto* casted = vector->as<T>();
63-
if ((casted != nullptr) && (vector.use_count() == 1)) {
65+
if ((casted != nullptr) && velox::BaseVector::recursivelyReusable(vector)) {
6466
return casted;
6567
}
6668
vector.reset();

0 commit comments

Comments
 (0)