velox: Projection got incorrect result with LazyVector

I add the following test case to ExprTest.cpp and got incorrect result.
TEST_F(ExprTest, lazyLoadBug) {
const vector_size_t size = 4;
auto valueAt = [](auto row) { return row; };
auto isNullAtColC0 = [](auto row) { return row; };
// [1, 1, 1, null]
auto inputC0 = makeFlatVector<int64_t>(
size, [](auto row) { return 1; }, [](auto row) { return row == 3; });
// [0, 1, 2, 3] if fully loaded
std::vector<vector_size_t> loadedRows;
VectorPtr inputC1 = std::make_shared<LazyVector>(
pool_.get(),
BIGINT(),
size,
std::make_unique<test::SimpleVectorLoader>([&](auto rows) {
for (auto row : rows) {
loadedRows.push_back(row);
}
return makeFlatVector<int64_t>(
rows.back() + 1, valueAt);
}));
// 1) can pass test, manually load LazyVector with allRows
// SelectivityVector allRows(size);
// LazyVector::ensureLoadedRows(inputC1, allRows);
// 2) can pass test, not using lazy vector
// auto inputC1 = makeFlatVector<int64_t>(
// size, valueAt, nullptr);
// isFinalSelection_ == true
auto result = evaluate(
"row_constructor(c0 + c1, if (c1 >= 0, c1, 0))", makeRowVector({inputC0, inputC1}));
// [1, 2, 3, null]
auto outputCol0 = makeFlatVector<int64_t>(
size, [](auto row) { return row + 1; }, [](auto row) { return row == 3; });
// [0, 1, 2, 3]
auto outputCol1 = makeFlatVector<int64_t>(
size, [](auto row) { return row; }, nullptr);
// [(1, 0), (2, 1), (3, 2), (null, 3)]
auto expected = ExprTest::makeRowVector({outputCol0, outputCol1});
assertEqualVectors(expected, result);
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 22 (22 by maintainers)
Commits related to this issue
- Fix finalSelection when null value's evalution (#2073) — committed to barsondei/velox by barsondei 2 years ago
- Fix finalSelection when skip null value's evalution (#2073) — committed to barsondei/velox by barsondei 2 years ago
- Fix finalSelection when skip null value's evalution (#2073) — committed to barsondei/velox by barsondei 2 years ago
- pre-loading lazy vectors at common parent expr or in ExprSet::eval (#2073) — committed to barsondei/velox by barsondei 2 years ago
- fix for review comments (#2073): 1) use distinctFields_ instead of allFields 2) rename variables, drop temp variables in ExprTest::lazyVectorAccessTwiceWithDifferentRows — committed to barsondei/velox by barsondei 2 years ago
- Fix finalSelection when skip null value's evalution (#2073) — committed to barsondei/velox by barsondei 2 years ago
- pre-loading lazy vectors at common parent expr or in ExprSet::eval (#2073) — committed to barsondei/velox by barsondei 2 years ago
- fix for review comments (#2073): 1) use distinctFields_ instead of allFields 2) rename variables, drop temp variables in ExprTest::lazyVectorAccessTwiceWithDifferentRows — committed to barsondei/velox by barsondei 2 years ago
- [GLUTEN-1963][CH] upgrade to clang-16 (#2073) — committed to marin-ma/velox-oap by lwz9103 a year ago
OK。I‘m pleasure to fix it。
I’m not clear with the logic of LazyVector’s creation in TableScan operator。 If it only load rows specified with bitmap,the bug will occur when run SQL in end to end environment: SQL: