Skip to content

Commit

Permalink
add null might contain test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchengchenghh committed Mar 9, 2023
1 parent 372b1b4 commit 893edb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 11 additions & 11 deletions velox/functions/sparksql/MightContain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ class BloomFilterMightContainFunction final : public exec::VectorFunction {
exec::DecodedArgs decodedArgs(rows, args, context);
auto serialized = decodedArgs.at(0);
auto value = decodedArgs.at(1);
if (serialized->isConstantMapping() && serialized->isNullAt(0)) {
rows.applyToSelected([&](int row) { result.setNull(row, true); });
return;
}

HashStringAllocator allocator{context.pool()};
if (serialized->isConstantMapping()) {
BloomFilter output{StlAllocator<uint64_t>(&allocator)};
output.merge(serialized->valueAt<StringView>(0).data());
rows.applyToSelected([&](int row) {
auto contain = output.mayContain(
folly::hasher<int64_t>()(value->valueAt<int64_t>(row)));
result.set(row, contain);
});
if (serialized->isNullAt(0)) {
rows.applyToSelected([&](int row) { result.set(row, false); });
} else {
BloomFilter output{StlAllocator<uint64_t>(&allocator)};
output.merge(serialized->valueAt<StringView>(0).data());
rows.applyToSelected([&](int row) {
auto contain = output.mayContain(
folly::hasher<int64_t>()(value->valueAt<int64_t>(row)));
result.set(row, contain);
});
}
return;
}

Expand Down
4 changes: 4 additions & 0 deletions velox/functions/sparksql/tests/MightContainTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ TEST_F(MightContainTest, common) {

EXPECT_FALSE(mightContain(serialized, kSize + 123451).value());
}

TEST_F(MightContainTest, null) {
EXPECT_FALSE(mightContain(std::nullopt, 12).value());
}
} // namespace
} // namespace facebook::velox::functions::sparksql::test

0 comments on commit 893edb1

Please sign in to comment.