spark-test commented on code in PR #60636:
URL: https://github.com/apache/spark/pull/60636#discussion_r4606873737


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/WholeStageCodegenSuite.scala:
##########
@@ -2376,17 +2376,19 @@ class WholeStageCodegenSuite extends SharedSparkSession
         val df = spark.range(10).select(
           f($"id").as("f"), r($"id").as("r"), rb($"id").as("rb"),
           rc($"id").as("rc"), u($"id").as("u"), n($"id").as("n"))
-        shapes.foreach { case Shape(predicate, inferredNotNullN) =>
+        shapes.foreach { predicate =>
           // Names the shape and the threshold in a failure, also when the 
query raises.
           withClue(s"methodSplitThreshold $threshold, $predicate: ") {
             try {
               val filtered = df.where(predicate)
               val fe = firstFilterOverProject(filtered)
-              if (inferredNotNullN) {
+              if (predicate.startsWith("n IS NOT NULL")) {
+                // The check drops the rows only if it is in the filter that 
reads `r`.

Review Comment:
   **Nit (P3):** The reason given here does not hold: `IsNotNull(n)` drops ids 
0 to 5 wherever it runs before `r` is computed, not only in the filter that 
reads `r`. From the optimizer code, with 
`spark.sql.optimizer.splitProjectionForExpensiveFilters` at its default of true 
(this test sets it to false at line 2375), `PushPredicateThroughNonJoin` would 
split the projection and put `isnotnull(n)` in its own filter below the 
projection that computes `r`. The rows would still be dropped before `r` is 
computed and the query would still return ids 6 to 9, but the first filter over 
a projection would then hold only `n + r > 0`, so this assertion would fail. 
Failing in that plan is the assertion's real job: the check and `n + r > 0` 
have to be in one filter for the shape to test what it is for, that `r` is 
loaded after the check. Read literally, the comment says a check elsewhere 
would not drop the rows; in that case `r` would throw and `checkAnswer` would 
already fail the test, so the asse
 rtion would look redundant.
   
   ```suggestion
                   // A check in a lower filter would also drop the rows before 
`r` is computed, and
                   // the shape would pass without testing that `r` is loaded 
after the check.
   ```
   
   **Verification:**
   - **Inspection:** Read the comment above the plan assertion for the `n IS 
NOT NULL` shape in WholeStageCodegenSuite.scala and confirm three things: it 
says that with the check in a lower filter the shape would pass without testing 
that `r` is loaded after the check, it does not say that a check in another 
filter would fail to drop the rows, and the assertion and its failure message 
are unchanged.



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