Raviston6296 opened a new pull request, #60132:
URL: https://github.com/apache/spark/pull/60132

   ### What changes were proposed in this pull request?
   
   `ParquetFilters.createFilterHelper` converts `sources.In` with more values 
than `spark.sql.parquet.pushdown.inFilterThreshold` into a Parquet `in` 
predicate. When the list contains NULL, the pushed filter is `col = NULL OR col 
IN (non-null values)`, built as `Seq(eq, in).flatten.reduceLeftOption(or)`.
   
   `makeInPredicate` had no case for BOOLEAN, the only type that `makeEq` 
supports and `makeInPredicate` does not. So for a BOOLEAN column the `in` 
disjunct was `None`, `flatten` dropped it, and the pushed filter became `col = 
NULL` alone. That is stricter than the original predicate, so Parquet skipped 
every row group without NULLs, including the ones holding the matching rows.
   
   This PR:
   1. Adds a BOOLEAN case to `makeInPredicate` (`FilterApi.in(booleanColumn(n), 
set)`), like the other types.
   2. Pushes `col = NULL OR col IN (...)` only when both disjuncts can be 
built, and pushes nothing otherwise, so a missing disjunct can never make the 
pushed filter stricter than the IN.
   
   ### Why are the changes needed?
   
   It is a correctness bug: the query silently returns fewer rows when Parquet 
filter pushdown is on (the default).
   
   ```python
   path = "/tmp/bool_in_null"
   spark.sql("SELECT * FROM VALUES (true), (false) AS 
t(b)").coalesce(1).write.mode("overwrite").parquet(path)
   spark.sql("SELECT CAST(NULL AS BOOLEAN) AS 
b").write.mode("append").parquet(path)
   spark.read.parquet(path).createOrReplaceTempView("t")
   
   q = "SELECT b FROM t WHERE b IN (true, NULL)"
   spark.sql(q).show()   # one row: true
   spark.conf.set("spark.sql.parquet.pushdown.inFilterThreshold", "1")
   spark.sql(q).show()   # before: no row; after: one row, true
   ```
   
   `b IN (true, false, NULL)` with threshold 2 also returned no row. It 
reproduces on 3.5.8, 4.0.0, 4.1.1, 4.2.0 and master.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, a bug fix. `IN` lists containing NULL on a BOOLEAN Parquet column now 
return the matching rows when the list is longer than 
`spark.sql.parquet.pushdown.inFilterThreshold`. Such lists are now also pushed 
down as a Parquet `in` predicate, as for the other types.
   
   ### How was this patch tested?
   
   New tests in `ParquetFilterSuite` (run by both `ParquetV1FilterSuite` and 
`ParquetV2FilterSuite`), which fail without this change:
   - `SPARK-60916: Pushdown IN predicate on a BOOLEAN column`: the pushed 
filter for `IN (true, false)` and `IN (true, NULL)`.
   - `SPARK-60916: IN with NULL on a BOOLEAN column above the IN filter 
threshold`: the end-to-end example above, with thresholds 1 and 10.
   
   ```
   build/sbt 'sql/testOnly *ParquetV1FilterSuite *ParquetV2FilterSuite' 
sql/scalastyle sql/Test/scalastyle
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to