diff --git a/cpp/velox/substrait/SubstraitToVeloxPlan.cc b/cpp/velox/substrait/SubstraitToVeloxPlan.cc index a9db5d031ec8..d36401cbe2ca 100644 --- a/cpp/velox/substrait/SubstraitToVeloxPlan.cc +++ b/cpp/velox/substrait/SubstraitToVeloxPlan.cc @@ -1639,24 +1639,36 @@ void SubstraitToVeloxPlanConverter::createNotEqualFilter( using NativeType = typename RangeTraits::NativeType; using RangeType = typename RangeTraits::RangeType; // Value > lower - std::unique_ptr lowerFilter = std::make_unique( - notVariant.value(), /*lower*/ - false, /*lowerUnbounded*/ - true, /*lowerExclusive*/ - getMax(), /*upper*/ - true, /*upperUnbounded*/ - false, /*upperExclusive*/ - nullAllowed); /*nullAllowed*/ + std::unique_ptr lowerFilter; + if constexpr (std::is_same_v) { + lowerFilter = std::make_unique( + notVariant.value() + 1 /*lower*/, getMax() /*upper*/, nullAllowed); + } else { + lowerFilter = std::make_unique( + notVariant.value() /*lower*/, + false /*lowerUnbounded*/, + true /*lowerExclusive*/, + getMax() /*upper*/, + true /*upperUnbounded*/, + false /*upperExclusive*/, + nullAllowed); + } // Value < upper - std::unique_ptr upperFilter = std::make_unique( - getLowest(), /*lower*/ - true, /*lowerUnbounded*/ - false, /*lowerExclusive*/ - notVariant.value(), /*upper*/ - false, /*upperUnbounded*/ - true, /*upperExclusive*/ - nullAllowed); /*nullAllowed*/ + std::unique_ptr upperFilter; + if constexpr (std::is_same_v) { + upperFilter = std::make_unique( + getLowest() /*lower*/, notVariant.value() - 1 /*upper*/, nullAllowed); + } else { + upperFilter = std::make_unique( + getLowest() /*lower*/, + true /*lowerUnbounded*/, + false /*lowerExclusive*/, + notVariant.value() /*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. @@ -1770,8 +1782,12 @@ void SubstraitToVeloxPlanConverter::setSubfieldFilter( dynamic_cast(b.get())->lower(); }); } - - filters[common::Subfield(inputName)] = std::make_unique(std::move(colFilters), nullAllowed); + if constexpr (std::is_same_v) { + filters[common::Subfield(inputName)] = + std::make_unique(std::move(colFilters), nullAllowed, true /*nanAllowed*/); + } else { + filters[common::Subfield(inputName)] = std::make_unique(std::move(colFilters), nullAllowed); + } } } @@ -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(std::move(colFilters), nullAllowed); + if constexpr (std::is_same_v) { + filters[common::Subfield(inputName)] = + std::make_unique(std::move(colFilters), nullAllowed, true /*nanAllowed*/); + } else { + filters[common::Subfield(inputName)] = std::make_unique(std::move(colFilters), nullAllowed); + } return; } @@ -1880,8 +1901,14 @@ void SubstraitToVeloxPlanConverter::constructSubfieldFilters( upperExclusive = filterInfo.upperExclusives_[idx]; } - std::unique_ptr filter = std::move(std::make_unique( - lowerBound, lowerUnbounded, lowerExclusive, upperBound, upperUnbounded, upperExclusive, nullAllowed)); + std::unique_ptr filter; + if constexpr (std::is_same_v) { + filter = std::move(std::make_unique( + lowerExclusive ? lowerBound + 1 : lowerBound, upperExclusive ? upperBound - 1 : upperBound, nullAllowed)); + } else { + filter = std::move(std::make_unique( + lowerBound, lowerUnbounded, lowerExclusive, upperBound, upperUnbounded, upperExclusive, nullAllowed)); + } colFilters.emplace_back(std::move(filter)); }