Skip to content

[SPARK-52032][SQL] Fix orc filter pushdown with null-safe equality operator #50932

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ private[sql] object OrcFilters extends OrcFiltersBase {
val rhs = buildSearchArgument(dataTypeMap, right, lhs)
rhs.end()

case Not(EqualNullSafe(name, value)) if dataTypeMap.contains(name) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val orFilter = Or(IsNull(name), Not(EqualTo(name, value)))
buildSearchArgument(dataTypeMap, orFilter, builder)

case Not(child) =>
buildSearchArgument(dataTypeMap, child, builder.startNot()).end()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,5 +816,34 @@ class OrcFilterSuite extends OrcTest with SharedSparkSession {
.equals("a.cint", OrcFilters.getPredicateLeafType(IntegerType), 2L)
.`end`().build())
}

test("SPARK-52032: filter pushdown with null-safe equality operator") {
withTempDir { dir =>
// Create test data
val data = Seq(
(1, "John", "john@example.com"),
(3, null, "bob@example.com")
)
val df = spark.createDataFrame(data).toDF("id", "name", "email")

// Write data in ORC format
val orcPath = s"${dir.getCanonicalPath}/orc"
df.write.mode("overwrite").orc(orcPath)

// Read data back and check for both enabled/disabled filter-pushdown
Seq(true, false).foreach { filterPushdown =>
withSQLConf("spark.sql.orc.filterPushdown" -> filterPushdown.toString) {
// Apply filter with null-safe equality operator
val df = spark.read.orc(orcPath).filter(!(col("name") <=> "dummy"))

// Check results
checkAnswer(df, Seq(
Row(1, "John", "john@example.com"),
Row(3, null, "bob@example.com")
))
}
}
}
}
}