Skip to content

Commit

Permalink
Fix crash when map subfield is pruned but we still want to add non-nu…
Browse files Browse the repository at this point in the history
…ll filter on its keys

Differential Revision: D56642855
  • Loading branch information
Yuhta authored and facebook-github-bot committed Apr 26, 2024
1 parent 97160cd commit 8ea17ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions velox/connectors/hive/HiveConnectorUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ namespace {

void filterOutNullMapKeys(const Type& rootType, common::ScanSpec& rootSpec) {
rootSpec.visit(rootType, [](const Type& type, common::ScanSpec& spec) {
if (type.isMap()) {
spec.childByName(common::ScanSpec::kMapKeysFieldName)
->addFilter(common::IsNotNull());
if (type.isMap() && !spec.isConstant()) {
auto* keys = spec.childByName(common::ScanSpec::kMapKeysFieldName);
VELOX_CHECK_NOT_NULL(keys);
keys->addFilter(common::IsNotNull());
}
});
}
Expand Down
19 changes: 19 additions & 0 deletions velox/connectors/hive/tests/HiveConnectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,25 @@ TEST_F(HiveConnectorTest, makeScanSpec_filterPartitionKey) {
ASSERT_FALSE(scanSpec->childByName("ds")->projectOut());
}

TEST_F(HiveConnectorTest, makeScanSpec_prunedMapNonNullMapKey) {
auto rowType =
ROW({"c0"},
{ROW(
{{"c0c0", MAP(BIGINT(), MAP(BIGINT(), BIGINT()))},
{"c0c1", BIGINT()}})});
auto scanSpec = makeScanSpec(
rowType,
groupSubfields(makeSubfields({"c0.c0c1"})),
{},
nullptr,
{},
{},
pool_.get());
auto* c0 = scanSpec->childByName("c0");
ASSERT_EQ(c0->children().size(), 2);
ASSERT_TRUE(c0->childByName("c0c0")->isConstant());
}

TEST_F(HiveConnectorTest, extractFiltersFromRemainingFilter) {
core::QueryCtx queryCtx;
exec::SimpleExpressionEvaluator evaluator(&queryCtx, pool_.get());
Expand Down
4 changes: 4 additions & 0 deletions velox/dwio/common/ScanSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ class ScanSpec {
template <typename F>
void ScanSpec::visit(const Type& type, F&& f) {
f(type, *this);
if (isConstant()) {
// Child specs are not populated in this case.
return;
}
switch (type.kind()) {
case TypeKind::ROW:
for (auto& child : children_) {
Expand Down

0 comments on commit 8ea17ca

Please sign in to comment.