Skip to content

Commit b44ffc9

Browse files
bikramSingh91facebook-github-bot
authored andcommitted
fix: Ensure flat input for functions that consume a single field (#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: #11822 Test Plan: Added a unit test Reviewed By: kevinwilfong Differential Revision: D67071147 Pulled By: bikramSingh91 fbshipit-source-id: 18c57ebb52b44674a0b5aafbc810b9e6dd119ed8
1 parent 3c73193 commit b44ffc9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

velox/expression/Expr.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,14 @@ bool Expr::applyFunctionWithPeeling(
14701470
LocalDecodedVector localDecoded(context);
14711471
LocalSelectivityVector newRowsHolder(context);
14721472
if (!context.peelingEnabled()) {
1473-
if (inputValues_.size() == 1) {
1473+
if (distinctFields_.size() < 2) {
14741474
// If we have a single input, velox needs to ensure that the
1475-
// vectorFunction would receive a flat input.
1476-
BaseVector::flattenVector(inputValues_[0]);
1475+
// vectorFunction would receive a flat or constant input.
1476+
for (int i = 0; i < inputValues_.size(); ++i) {
1477+
if (inputValues_[i]->encoding() == VectorEncoding::Simple::DICTIONARY) {
1478+
BaseVector::flattenVector(inputValues_[i]);
1479+
}
1480+
}
14771481
applyFunction(applyRows, context, result);
14781482
return true;
14791483
}

velox/expression/tests/ExprTest.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -4861,6 +4861,15 @@ TEST_F(ExprTest, disablePeeling) {
48614861
makeRowVector({flatInput}),
48624862
{},
48634863
execCtx.get()));
4864+
4865+
// Ensure functions that take a single column as input but can have more
4866+
// constant inputs also receive a flat vector. We use the in-predicate in this
4867+
// case which has a check for ensuring flat input.
4868+
ASSERT_NO_THROW(evaluateMultiple(
4869+
{"dict_wrap(c0) in (40, 42)"},
4870+
makeRowVector({flatInput}),
4871+
{},
4872+
execCtx.get()));
48644873
}
48654874

48664875
TEST_F(ExprTest, disableSharedSubExpressionReuse) {

0 commit comments

Comments
 (0)