dongjoon-hyun opened a new pull request, #60650:
URL: https://github.com/apache/spark/pull/60650

   ### What changes were proposed in this pull request?
   
   This PR fixes the shape `n + r > 0 AND f + 1 > 0 AND f + 1 < 100` that 
#60557 added to `SPARK-61377: FilterExec CSE computes an input column just 
before the first conjunct that reads it` in `WholeStageCodegenSuite`. The shape 
relied on `InferFiltersFromConstraints` inferring `IsNotNull(n)` over the UDF 
alias `n`. Since #60574 (SPARK-61823), the rule does not infer a filter over a 
column that can fail, such as an alias of a UDF, so the test fails where it 
asserts that the check is inferred:
   
   ```
   IsNotNull(n) should be inferred: ((((n#18L + r#6L) > 0) AND ((f#3L + 1) > 
0)) AND ((f#3L + 1) < 100)) (WholeStageCodegenSuite.scala:2386)
   ```
   
   The shape now writes the check out: `n IS NOT NULL AND n + r > 0 AND f + 1 > 
0 AND f + 1 < 100`. This is the condition that the inference produced before 
#60574, with the check in the same place, so `FilterExec` generates the same 
code for it: the check is generated among the checks of `n + r > 0`, the first 
condition that reads `r`, and `r` is loaded after it. The assertion now checks 
that `IsNotNull(n)` is in the filter over the projection, and the flag and the 
comments no longer say that the check is inferred.
   
   A nullable column that cannot fail would not keep the shape either: a `CASE 
WHEN` alias can fail too, and a check inferred over a column computed below the 
projection is pushed below it, so no check is left in the filter over the 
projection.
   
   ### Why are the changes needed?
   
   #60557 and #60574 each passed CI, but the CI of #60557 ran on a `master` 
without #60574. With both, the test fails on `master` and `branch-4.x`, e.g. in 
the [non-ANSI build of 
`branch-4.x`](https://github.com/apache/spark/actions/runs/44106415721). 
Without the check, the shape no longer tests what it was added for: the query 
fails as well, as `r` raises its error on the rows that the check dropped.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This changes a test only.
   
   ### How was this patch tested?
   
   - The test fails on `master` without this PR, and passes with it, also with 
`SPARK_ANSI_SQL_MODE=false`. `WholeStageCodegenSuite` passes.
   - With `spark.sql.codegen.methodSplitThreshold` at 1 and at `Int.MaxValue`, 
the new condition on `master` generates the same Java code as the old condition 
did with the inference, i.e. on `master` with the check that #60574 added to 
`InferFiltersFromConstraints` removed.
   - The two mutants of `generatePredicateCode` that #60557 added the shape for 
still fail the test at this shape, with `r` raising its error: (a) loading the 
columns of a conjunct before all the checks generated for it, and (b) loading 
them after the checks that `precedingNotNullChecks` generates for it, but 
before its other checks.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   


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