Skip to content

Commit e5d4474

Browse files
MatzeBfacebook-github-bot
authored andcommitted
fix(nimble): Preserve nulls in dense bulk reads
Summary: Bugfix: Dense nullable reads using an `AlwaysTrue` visitor could return an all-valid vector even when the input contained nulls. The bulk path now copies the read-range null bitmap when the reader cannot return that buffer directly, then marks the result as nullable. Differential Revision: D116851691
1 parent c3413b2 commit e5d4474

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

velox/dwio/nimble/encodings/common/Encoding.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,20 @@ void readWithVisitorFast(
687687
auto numNonNulls = velox::simd::indicesOfSetBits(
688688
nulls, visitor.rowIndex(), visitor.numRows(), outerRows.data());
689689
outerRows.resize(numNonNulls);
690+
if constexpr (kOutputNulls) {
691+
if (numNonNulls != numRows) {
692+
if (!visitor.reader().returnReaderNulls()) {
693+
params.prepareResultNulls();
694+
velox::bits::copyBits(
695+
nulls,
696+
visitor.rowIndex(),
697+
visitor.reader().rawResultNulls(),
698+
visitor.rowIndex(),
699+
numRows);
700+
}
701+
visitor.setHasNulls();
702+
}
703+
}
690704
if (outerRows.empty()) {
691705
if constexpr (kOutputNulls) {
692706
visitor.addNumValues(numRows);

velox/dwio/nimble/encodings/tests/ReadWithVisitorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,14 @@ TEST_P(ReadWithVisitorTest, denseNoFilterWithNulls) {
748748
// Every row is "output" since there is no filter.
749749
EXPECT_EQ(child->numValues(), kRows);
750750
EXPECT_TRUE(child->hasNulls());
751+
752+
std::vector<vector_size_t> rowNumbers(kRows);
753+
std::iota(rowNumbers.begin(), rowNumbers.end(), 0);
754+
VectorPtr result;
755+
child->getValues(RowSet(rowNumbers.data(), rowNumbers.size()), &result);
756+
for (int i = 0; i < kRows; ++i) {
757+
EXPECT_EQ(result->isNullAt(i), i % 7 == 0) << "row " << i;
758+
}
751759
}
752760

753761
// ===========================================================================

0 commit comments

Comments
 (0)