diff --git a/velox/vector/ComplexVector.cpp b/velox/vector/ComplexVector.cpp index 49abf754c4b5..2a1e95e6dfbf 100644 --- a/velox/vector/ComplexVector.cpp +++ b/velox/vector/ComplexVector.cpp @@ -541,8 +541,9 @@ void ArrayVectorBase::copyRangesImpl( auto sourceArray = leafSource->asUnchecked(); auto setNotNulls = mayHaveNulls() || source->mayHaveNulls(); - auto* mutableOffsets = offsets_->asMutable(); - auto* mutableSizes = sizes_->asMutable(); + auto* mutableOffsets = + this->mutableOffsets(length_)->asMutable(); + auto* mutableSizes = this->mutableSizes(length_)->asMutable(); vector_size_t childSize = targetValues->get()->size(); if (ranges.size() == 1 && ranges.back().count == 1) { auto& range = ranges.back(); diff --git a/velox/vector/tests/VectorTest.cpp b/velox/vector/tests/VectorTest.cpp index 6711347ed8ba..c179249f1cb3 100644 --- a/velox/vector/tests/VectorTest.cpp +++ b/velox/vector/tests/VectorTest.cpp @@ -3773,5 +3773,17 @@ TEST_F(VectorTest, mapUpdateMultipleUpdates) { } } +TEST_F(VectorTest, arrayCopyTargetNullOffsets) { + auto target = BaseVector::create(ARRAY(BIGINT()), 11, pool()); + auto offsetsRef = target->asUnchecked()->offsets(); + ASSERT_TRUE(offsetsRef); + BaseVector::prepareForReuse(target, target->size()); + ASSERT_FALSE(target->asUnchecked()->offsets()); + auto source = makeArrayVector( + 11, [](auto) { return 1; }, [](auto i, auto) { return i; }); + target->copy(source.get(), 0, 0, source->size()); + test::assertEqualVectors(source, target); +} + } // namespace } // namespace facebook::velox