sarutak commented on PR #59940:
URL: https://github.com/apache/spark/pull/59940#issuecomment-6810727247

   Two updates on the changes this PR waits for, and a gap of this PR that I 
found, cc @dongjoon-hyun.
   
   1. SPARK-61437 is to land before this PR, and SPARK-61354 no longer needs 
to. I narrowed SPARK-61354 (#60337) to non-deterministic conditions: 
`ConstantPropagation` still moves an equality forward as on master, but only up 
to the last non-deterministic condition written before it. So #60337 no longer 
fixes the two queries from my [earlier 
comment](https://github.com/apache/spark/pull/59940#issuecomment-6764912323), 
over the Parquet table with the rows `("1", 1)` and `("x", 0)`: with #60337 
applied on top of this PR and ANSI mode on, `f > 0 && i * id > 0 && i = 1` and 
`f > 0 && i > 0 && 10 / (id - 3) > 0 && i = 1`, with `f` an identity Scala UDF 
and `i` the alias `cast(s as int)`, still fail with `CAST_INVALID_INPUT`, with 
the projection split and whole-stage codegen on or off. `ConstantPropagation` 
moves `i = 1` in front of `f > 0`, since a condition that can fail reads `i` 
(`i * id > 0`) or comes after a condition it rewrites (`10 / (id - 3) > 0` 
after `i > 0`), and it treats the
  move as safe, as it only sees the attribute `i`, not the cast `i` stands for 
in the projection below. This rule then pushes `i = 1` below the projection as 
`cast(s as int) = 1`. SPARK-61437 is to fix that. SPARK-61354 changes the rows 
a non-deterministic condition sees in the same way with and without this PR, so 
this PR does not need to wait for it.
   
   2. The checks this PR adds, `canPushAhead`, the one after a condition over a 
Python UDF and the one that keeps the filter unsplit, only substitute the 
aliases of the projection the filter is on, so they miss a column that a 
projection below it defines, also with filters in between. With `f` as above, 
`spark.range(0, 10, 1, 1).select($"id", (lit(10L) / ($"id" - 
3)).as("x")).select($"id", $"x", f($"id").as("f")).where($"f" > 5 && $"x" > 
0)`, and the same with `withColumn("x", ...).withColumn("f", ...)`, fail with 
`DIVIDE_BY_ZERO` in ANSI mode with this PR, with the split on or off, and also 
on 4.2.0 and 4.3.0, while 4.1.4 returns the ids 6 to 9: `x` is a plain column 
in the upper projection, so the rule pushes `x > 0`, and then pushes it through 
the projection that defines `x`, which has no expensive alias and so holds 
nothing back. Over a Parquet table with the rows `("1", 7)` and `("x", 0)`, `f 
> 0 && i = 1` with `i = cast(s as int)` in the lower projection fails with 
`CAST_INVALI
 D_INPUT` the same way, also with `where($"id" >= 0)` between the projections, 
while 4.1.4 returns the row `("1", 7)`. I will fix these checks in the push 
that rebases this PR onto the changes above, so that they see what such a 
column computes, with tests for these queries. The division query also needs 
SPARK-61378: it also fails through the `isnotnull(x)` that 
`InferFiltersFromConstraints` puts in front, as it does with `x` and `f` in one 
projection.
   
      The `throwable` checks of SPARK-60602 have the same gap on master: over 
the same table, with `j = CASE WHEN s = 'x' THEN raise_error('boom') ELSE 1 
END` in the lower projection, `f > 0 && j = 1` fails with 
`USER_RAISED_EXCEPTION` on master, and with this PR also with 
`spark.sql.legacy.pushFilterAheadOfExpensiveConjunct` on, while it succeeds 
with `j` in the same projection. With the legacy config off, the fixed checks 
of this PR should keep such a condition above. I filed SPARK-61491 for the 
legacy path and the projection split, as that is a gap of SPARK-60602 itself, 
which also went to branch-4.3 and branch-4.2.
   
   The two code comments in `Optimizer.scala` that name SPARK-61354 for the 
equalities `ConstantPropagation` moves will be updated with the other sentences 
in that push. I updated the description: the changes to land first are now 
SPARK-60731, SPARK-61377, SPARK-61378 and SPARK-61437. Please hold off merging 
this PR until they are in and the gap above is fixed.
   


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