diff --git a/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala b/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala index a14a5b7e78de..abc9c8811063 100644 --- a/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala +++ b/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala @@ -106,6 +106,12 @@ class TestOperator extends VeloxWholeStageTransformerSuite { checkLengthAndPlan(df, 6) } + test("is_null and is_not_null coexist") { + val df = runQueryAndCompare( + "select l_orderkey from lineitem where l_comment is null and l_comment is not null") { _ => } + checkLengthAndPlan(df, 0) + } + test("and pushdown") { val df = runQueryAndCompare( "select l_orderkey from lineitem where l_orderkey > 2 " + diff --git a/cpp/velox/substrait/SubstraitToVeloxPlan.cc b/cpp/velox/substrait/SubstraitToVeloxPlan.cc index 4b1a2543e7c3..24abc5a6580d 100644 --- a/cpp/velox/substrait/SubstraitToVeloxPlan.cc +++ b/cpp/velox/substrait/SubstraitToVeloxPlan.cc @@ -2036,6 +2036,7 @@ void SubstraitToVeloxPlanConverter::constructSubfieldFilters( bool nullAllowed = filterInfo.nullAllowed_; bool isNull = filterInfo.isNull_; + bool existIsNullAndIsNotNull = filterInfo.forbidsNullSet_ && filterInfo.isNullSet_; uint32_t rangeSize = std::max(filterInfo.lowerBounds_.size(), filterInfo.upperBounds_.size()); if constexpr (KIND == facebook::velox::TypeKind::HUGEINT) { @@ -2122,7 +2123,10 @@ void SubstraitToVeloxPlanConverter::constructSubfieldFilters( // Handle null filtering. if (rangeSize == 0) { - if (!nullAllowed) { + // handle is not null and is null exists at same time + if (existIsNullAndIsNotNull) { + filters[common::Subfield(inputName)] = std::move(std::make_unique()); + } else if (!nullAllowed) { filters[common::Subfield(inputName)] = std::make_unique(); } else if (isNull) { filters[common::Subfield(inputName)] = std::make_unique(); diff --git a/cpp/velox/substrait/SubstraitToVeloxPlan.h b/cpp/velox/substrait/SubstraitToVeloxPlan.h index dc97d2a4cf60..1bda6435eaee 100644 --- a/cpp/velox/substrait/SubstraitToVeloxPlan.h +++ b/cpp/velox/substrait/SubstraitToVeloxPlan.h @@ -316,6 +316,7 @@ class SubstraitToVeloxPlanConverter { if (!initialized_) { initialized_ = true; } + forbidsNullSet_ = true; } // Only null is allowed. @@ -325,6 +326,7 @@ class SubstraitToVeloxPlanConverter { if (!initialized_) { initialized_ = true; } + isNullSet_ = true; } // Return the initialization status. @@ -375,6 +377,8 @@ class SubstraitToVeloxPlanConverter { bool nullAllowed_ = false; bool isNull_ = false; + bool forbidsNullSet_ = false; + bool isNullSet_ = false; // If true, left bound will be exclusive. std::vector lowerExclusives_;