Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL] Use existing constructor for BigintRange and MultiRange #3508

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 48 additions & 21 deletions cpp/velox/substrait/SubstraitToVeloxPlan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1639,24 +1639,36 @@ void SubstraitToVeloxPlanConverter::createNotEqualFilter(
using NativeType = typename RangeTraits<KIND>::NativeType;
using RangeType = typename RangeTraits<KIND>::RangeType;
// Value > lower
std::unique_ptr<FilterType> lowerFilter = std::make_unique<RangeType>(
notVariant.value<NativeType>(), /*lower*/
false, /*lowerUnbounded*/
true, /*lowerExclusive*/
getMax<NativeType>(), /*upper*/
true, /*upperUnbounded*/
false, /*upperExclusive*/
nullAllowed); /*nullAllowed*/
std::unique_ptr<FilterType> lowerFilter;
if constexpr (std::is_same_v<RangeType, common::BigintRange>) {
lowerFilter = std::make_unique<common::BigintRange>(
notVariant.value<NativeType>() + 1 /*lower*/, getMax<NativeType>() /*upper*/, nullAllowed);
} else {
lowerFilter = std::make_unique<RangeType>(
notVariant.value<NativeType>() /*lower*/,
false /*lowerUnbounded*/,
true /*lowerExclusive*/,
getMax<NativeType>() /*upper*/,
true /*upperUnbounded*/,
false /*upperExclusive*/,
nullAllowed);
}

// Value < upper
std::unique_ptr<FilterType> upperFilter = std::make_unique<RangeType>(
getLowest<NativeType>(), /*lower*/
true, /*lowerUnbounded*/
false, /*lowerExclusive*/
notVariant.value<NativeType>(), /*upper*/
false, /*upperUnbounded*/
true, /*upperExclusive*/
nullAllowed); /*nullAllowed*/
std::unique_ptr<FilterType> upperFilter;
if constexpr (std::is_same_v<RangeType, common::BigintRange>) {
upperFilter = std::make_unique<common::BigintRange>(
getLowest<NativeType>() /*lower*/, notVariant.value<NativeType>() - 1 /*upper*/, nullAllowed);
} else {
upperFilter = std::make_unique<RangeType>(
getLowest<NativeType>() /*lower*/,
true /*lowerUnbounded*/,
false /*lowerExclusive*/,
notVariant.value<NativeType>() /*upper*/,
false /*upperUnbounded*/,
true /*upperExclusive*/,
nullAllowed);
}

// To avoid overlap of BigintMultiRange, keep this appending order to make sure lower bound of one range is less than
// the upper bounds of others.
Expand Down Expand Up @@ -1770,8 +1782,12 @@ void SubstraitToVeloxPlanConverter::setSubfieldFilter(
dynamic_cast<common::BigintRange*>(b.get())->lower();
});
}

filters[common::Subfield(inputName)] = std::make_unique<MultiRangeType>(std::move(colFilters), nullAllowed);
if constexpr (std::is_same_v<MultiRangeType, common::MultiRange>) {
filters[common::Subfield(inputName)] =
std::make_unique<common::MultiRange>(std::move(colFilters), nullAllowed, true /*nanAllowed*/);
} else {
filters[common::Subfield(inputName)] = std::make_unique<MultiRangeType>(std::move(colFilters), nullAllowed);
}
}
}

Expand Down Expand Up @@ -1826,7 +1842,12 @@ void SubstraitToVeloxPlanConverter::constructSubfieldFilters(
// Currently, Not-equal cannot coexist with other filter conditions
// due to multirange is in 'OR' relation but 'AND' is needed.
VELOX_CHECK(rangeSize == 0, "LowerBounds or upperBounds conditons cannot be supported after not-equal filter.");
filters[common::Subfield(inputName)] = std::make_unique<MultiRangeType>(std::move(colFilters), nullAllowed);
if constexpr (std::is_same_v<MultiRangeType, common::MultiRange>) {
filters[common::Subfield(inputName)] =
std::make_unique<common::MultiRange>(std::move(colFilters), nullAllowed, true /*nanAllowed*/);
} else {
filters[common::Subfield(inputName)] = std::make_unique<MultiRangeType>(std::move(colFilters), nullAllowed);
}
return;
}

Expand Down Expand Up @@ -1880,8 +1901,14 @@ void SubstraitToVeloxPlanConverter::constructSubfieldFilters(
upperExclusive = filterInfo.upperExclusives_[idx];
}

std::unique_ptr<FilterType> filter = std::move(std::make_unique<RangeType>(
lowerBound, lowerUnbounded, lowerExclusive, upperBound, upperUnbounded, upperExclusive, nullAllowed));
std::unique_ptr<FilterType> filter;
if constexpr (std::is_same_v<RangeType, common::BigintRange>) {
filter = std::move(std::make_unique<common::BigintRange>(
lowerExclusive ? lowerBound + 1 : lowerBound, upperExclusive ? upperBound - 1 : upperBound, nullAllowed));
} else {
filter = std::move(std::make_unique<RangeType>(
lowerBound, lowerUnbounded, lowerExclusive, upperBound, upperUnbounded, upperExclusive, nullAllowed));
}

colFilters.emplace_back(std::move(filter));
}
Expand Down
Loading