dongjoon-hyun commented on code in PR #60772:
URL: https://github.com/apache/spark/pull/60772#discussion_r4653807860
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2871,10 +2871,13 @@ object PushPredicateThroughNonJoin extends
Rule[LogicalPlan] with PredicateHelpe
// split orders conditions by cost, and cost is no way to decide how
many rows a
// non-deterministic expression sees. Throwable conditions, or
conditions over throwable
// aliases, stay there too: ordering by cost could evaluate them (or
compute the aliases
- // in a lower projection) ahead of the conditions written before them.
+ // in a lower projection) ahead of the conditions written before them.
So do all the
+ // conditions written after the first of these: each reads an
expensive alias, e.g. a UDF
+ // or a regex whose pattern comes from the data, which can fail, so a
lower layer must
+ // not evaluate it on the rows that condition filters out.
val (splitChild, splitAliases, stayUp) =
if (expensiveWithUsed.nonEmpty &&
SQLConf.get.splitProjectionForExpensiveFilters) {
- val (splittable, notSplittable) = expensiveWithUsed.partition {
+ val (splittable, notSplittable) = expensiveWithUsed.span {
Review Comment:
Thank you. I confirmed both consequences in Spark, in ANSI mode with
whole-stage codegen on and off:
- The e2e query with `$"n" > 0 &&` written first fails with
`CAST_INVALID_INPUT` on `master` and with this PR.
- Your second query returns 9 rows on `master`, but fails with
`CAST_INVALID_INPUT` with this PR.
In both, the split computes `n`, or `a` and `b`, in a lower layer, and the
next pass of `PushPredicateThroughNonJoin` pushes the cast below the projection
as a cheap conjunct, ahead of the non-deterministic one. Holding such a
conjunct back is the `splitPushable` change of #60766 (SPARK-62144): once a
non-deterministic or throwable conjunct stays above, a later conjunct is pushed
only when `ExprUtils.canEvaluateUnconditionally` accepts it and it reads no
column that `failableOutput` reports, such as a UDF column of the lower layer.
With #60766 and this PR together, both queries return 9 rows.
So I'll rebase this PR onto #60766 after it is merged, and add both queries
to the tests.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2871,10 +2871,13 @@ object PushPredicateThroughNonJoin extends
Rule[LogicalPlan] with PredicateHelpe
// split orders conditions by cost, and cost is no way to decide how
many rows a
// non-deterministic expression sees. Throwable conditions, or
conditions over throwable
// aliases, stay there too: ordering by cost could evaluate them (or
compute the aliases
- // in a lower projection) ahead of the conditions written before them.
+ // in a lower projection) ahead of the conditions written before them.
So do all the
+ // conditions written after the first of these: each reads an
expensive alias, e.g. a UDF
Review Comment:
Right. This is the case that #60766 (SPARK-62144) fixes in `splitPushable`.
Your query fails with `CAST_INVALID_INPUT` on `master` and with this PR, and
returns 8 rows with #60766. I'll keep this PR to the split, and update this
comment after rebasing onto #60766, as it keeps such a cheap conjunct above too.
--
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]