Skip to content

Commit

Permalink
fix: Ensure flat input for functions that consume a single field
Browse files Browse the repository at this point in the history
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.

Test Plan:
Added a unit test
  • Loading branch information
bikramSingh91 committed Dec 11, 2024
1 parent b9cce6d commit ebd15ab
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 ebd15ab

Please sign in to comment.