From f5bbde6ea59594be35ad2dc06c6a5361942ec97e Mon Sep 17 00:00:00 2001 From: Masha Basmanova Date: Tue, 3 Oct 2023 15:10:14 -0700 Subject: [PATCH] Remove unsafe RowVector::resize call from HashProbe::fillFilterInput (#6869) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/6869 Reviewed By: xiaoxmeng Differential Revision: D49872243 Pulled By: mbasmanova fbshipit-source-id: e6cac46db5cdbda7b580171ab66d466e5cac710a --- velox/exec/HashProbe.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/velox/exec/HashProbe.cpp b/velox/exec/HashProbe.cpp index f94049909cce..16ab8331dfad 100644 --- a/velox/exec/HashProbe.cpp +++ b/velox/exec/HashProbe.cpp @@ -59,14 +59,18 @@ void extractColumns( folly::Range rows, folly::Range projections, memory::MemoryPool* pool, - const RowVectorPtr& result) { + const std::vector& resultTypes, + std::vector& resultVectors) { + VELOX_CHECK_EQ(resultTypes.size(), resultVectors.size()) for (auto projection : projections) { - auto& child = result->childAt(projection.outputChannel); + const auto resultChannel = projection.outputChannel; + VELOX_CHECK_LT(resultChannel, resultVectors.size()) + + auto& child = resultVectors[resultChannel]; // TODO: Consider reuse of complex types. if (!child || !BaseVector::isVectorWritable(child) || !child->isFlatEncoding()) { - child = BaseVector::create( - result->type()->childAt(projection.outputChannel), rows.size(), pool); + child = BaseVector::create(resultTypes[resultChannel], rows.size(), pool); } child->resize(rows.size()); table->rows()->extractColumn( @@ -714,7 +718,8 @@ void HashProbe::fillOutput(vector_size_t size) { folly::Range(outputTableRows_.data(), size), tableOutputProjections_, pool(), - output_); + outputType_->children(), + output_->children()); } } @@ -758,7 +763,8 @@ RowVectorPtr HashProbe::getBuildSideOutput() { folly::Range(outputTableRows_.data(), numOut), tableOutputProjections_, pool(), - output_); + outputType_->children(), + output_->children()); if (isRightSemiProjectJoin(joinType_)) { // Populate 'match' column. @@ -973,13 +979,10 @@ RowVectorPtr HashProbe::getOutput() { } void HashProbe::fillFilterInput(vector_size_t size) { - if (!filterInput_) { - filterInput_ = BaseVector::create(filterInputType_, 1, pool()); - } - filterInput_->resize(size); + std::vector filterColumns(filterInputType_->size()); for (auto projection : filterInputProjections_) { ensureLoadedIfNotAtEnd(projection.inputChannel); - filterInput_->childAt(projection.outputChannel) = wrapChild( + filterColumns[projection.outputChannel] = wrapChild( size, outputRowMapping_, input_->childAt(projection.inputChannel)); } @@ -988,7 +991,11 @@ void HashProbe::fillFilterInput(vector_size_t size) { folly::Range(outputTableRows_.data(), size), filterTableProjections_, pool(), - filterInput_); + filterInputType_->children(), + filterColumns); + + filterInput_ = std::make_shared( + pool(), filterInputType_, nullptr, size, std::move(filterColumns)); } void HashProbe::prepareFilterRowsForNullAwareJoin(