Skip to content

Commit

Permalink
Use existing constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Oct 25, 2023
1 parent 277d1c4 commit 9a91d6d
Showing 1 changed file with 48 additions and 21 deletions.
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

0 comments on commit 9a91d6d

Please sign in to comment.