Skip to content

Commit

Permalink
fix: Ensure flat input for functions that consume a single field (fac…
Browse files Browse the repository at this point in the history
…ebookincubator#11822)

Summary:
Ensure that Velox's guarantee that functions consuming a single field
reference as input always receive a flat input holds, even when the
debug query config disables peeling is turned on.

Pull Request resolved: facebookincubator#11822

Test Plan: Added a unit test

Reviewed By: kevinwilfong

Differential Revision: D67071147

Pulled By: bikramSingh91

fbshipit-source-id: 18c57ebb52b44674a0b5aafbc810b9e6dd119ed8
  • Loading branch information
bikramSingh91 authored and facebook-github-bot committed Dec 11, 2024
1 parent 3c73193 commit b44ffc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions velox/expression/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,10 +1470,14 @@ bool Expr::applyFunctionWithPeeling(
LocalDecodedVector localDecoded(context);
LocalSelectivityVector newRowsHolder(context);
if (!context.peelingEnabled()) {
if (inputValues_.size() == 1) {
if (distinctFields_.size() < 2) {
// If we have a single input, velox needs to ensure that the
// vectorFunction would receive a flat input.
BaseVector::flattenVector(inputValues_[0]);
// vectorFunction would receive a flat or constant input.
for (int i = 0; i < inputValues_.size(); ++i) {
if (inputValues_[i]->encoding() == VectorEncoding::Simple::DICTIONARY) {
BaseVector::flattenVector(inputValues_[i]);
}
}
applyFunction(applyRows, context, result);
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions velox/expression/tests/ExprTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4861,6 +4861,15 @@ TEST_F(ExprTest, disablePeeling) {
makeRowVector({flatInput}),
{},
execCtx.get()));

// Ensure functions that take a single column as input but can have more
// constant inputs also receive a flat vector. We use the in-predicate in this
// case which has a check for ensuring flat input.
ASSERT_NO_THROW(evaluateMultiple(
{"dict_wrap(c0) in (40, 42)"},
makeRowVector({flatInput}),
{},
execCtx.get()));
}

TEST_F(ExprTest, disableSharedSubExpressionReuse) {
Expand Down

0 comments on commit b44ffc9

Please sign in to comment.