raviston commented on code in PR #60132:
URL: https://github.com/apache/spark/pull/60132#discussion_r4549585777


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilters.scala:
##########
@@ -793,6 +793,14 @@ class ParquetFilters(
   private val makeInPredicate:
     PartialFunction[ParquetSchemaType, (Array[String], Array[Any]) => 
FilterPredicate] = {
 
+    case ParquetBooleanType =>
+      (n: Array[String], values: Array[Any]) =>
+        val set = new HashSet[JBoolean]()
+        for (value <- values) {
+          set.add(value.asInstanceOf[JBoolean])
+        }
+        FilterApi.in(booleanColumn(n), set)

Review Comment:
   Thanks, confirmed. With bloom filters on, `b IN (true, false)` at threshold 
1 failed the scan in V1 and V2 with `RuntimeException: Parquet Bloom filter: 
Not supported type` from `BloomFilterImpl.visit(In)` 
(`BloomFilterImpl.java:158`). The fix is the one you suggested:
   - The BOOLEAN case of `makeInPredicate` now builds an OR of `FilterApi.eq` 
per distinct value, in list order, with a comment explaining why.
   - Every route that pushes a BOOLEAN IN above the threshold goes through it, 
including the shredded-variant IN conversion, so parquet-java no longer gets an 
`in` on a BOOLEAN column.
   
   New tests:
   - `SPARK-60916: IN on a BOOLEAN column with a bloom filter above the IN 
filter threshold` writes a top-level `b` and a struct field `s.x` with 
`parquet.bloom.filter.enabled=true`. With threshold 1, it checks `IN (true, 
false)` and `IN (true, NULL)` with both readers, in V1 and V2.
   - `SPARK-60916: BOOLEAN IN above the IN filter threshold with a bloom 
filter` in `VariantShreddingFilterPushdownSuite` does the same for a variant 
field shredded as BOOLEAN, against the no-pushdown baseline.
   
   Both tests fail on the previous head with that error. The predicate-shape 
test now expects `or(eq(b, true), eq(b, false))` for `IN (true, false, true)`.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilters.scala:
##########
@@ -1242,9 +1250,11 @@ class ParquetFilters(
           }.reduceLeftOption(FilterApi.or)
         } else if (canPartialPushDownConjuncts) {
           if (values.contains(null)) {
-            Seq(makeEq.lift(fieldType).map(_(fieldNames, null)),
-              makeInPredicate.lift(fieldType).map(_(fieldNames, 
values.filter(_ != null)))
-            ).flatten.reduceLeftOption(FilterApi.or)
+            // Push both disjuncts or neither: either one alone is stricter 
than the IN.
+            for {
+              eqNull <- makeEq.lift(fieldType).map(_(fieldNames, null))
+              in <- makeInPredicate.lift(fieldType).map(_(fieldNames, 
values.filter(_ != null)))

Review Comment:
   Confirmed: `values in SetColumnFilterPredicate shouldn't be empty!`. When 
the list has only NULLs, the branch now pushes the IS NULL disjunct alone, as 
below the threshold, for every type. `SPARK-60916: IN with only NULLs above the 
IN filter threshold` checks two things:
   - The predicate is `eq(b, null)` for a BOOLEAN column and `eq(i, null)` for 
an INT one.
   - With `OptimizeIn` excluded, `b IN (NULL, NULL)` and `i IN (NULL, NULL)` 
return no rows, end to end.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilters.scala:
##########
@@ -1242,9 +1250,11 @@ class ParquetFilters(
           }.reduceLeftOption(FilterApi.or)
         } else if (canPartialPushDownConjuncts) {
           if (values.contains(null)) {
-            Seq(makeEq.lift(fieldType).map(_(fieldNames, null)),
-              makeInPredicate.lift(fieldType).map(_(fieldNames, 
values.filter(_ != null)))
-            ).flatten.reduceLeftOption(FilterApi.or)
+            // Push both disjuncts or neither: either one alone is stricter 
than the IN.

Review Comment:
   Thanks, fixed both comments:
   - Here: "The IN never keeps a NULL row, so its IS NULL disjunct alone would 
be stricter than the IN. Push it only together with the `in` disjunct, and push 
nothing otherwise."
   - In the test: "The pushed filter must not be `eq(b, null)` (IS NULL) alone: 
the IN never keeps a NULL row, so IS NULL alone would drop the rows that are 
true." 
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilterSuite.scala:
##########
@@ -1896,6 +1896,45 @@ abstract class ParquetFilterSuite extends ParquetTest 
with SharedSparkSession {
     }
   }
 
+  test("SPARK-60916: Pushdown IN predicate on a BOOLEAN column") {

Review Comment:
   Done. `filter pushdown - boolean` now runs `In(b, [true, false])` and `In(b, 
[true, NULL])` through `checkFilterPredicate` at thresholds 1 and 10, and 
expects `Operators.Or` at both, since BOOLEAN is now pushed as equalities on 
either side of the threshold. That covers the top-level and nested columns, the 
record-level filter with the vectorized reader off and Spark's Filter stripped, 
and V1 and V2.
   



-- 
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