sarutak commented on PR #60366:
URL: https://github.com/apache/spark/pull/60366#issuecomment-6865631060
Thank you, this was very helpful. I took your `tryEvalExpr` suggestion and
reworked the PR around
it, which changed it enough that I force-pushed a new version; this
supersedes several of my
earlier replies, listed at the end.
SPARK-61444 (#60325) already adds the `NonFatal` fallback in `tryEvalExpr`,
and both
`RewriteCorrelatedScalarSubquery.constructLeftJoins` and
`DecorrelateInnerQuery` reach it (the
latter through `evalAggregateOnZeroTups` -> `evalAggExprOnZeroTups` ->
`tryEvalExpr`), so that one
fix keeps a failing foldable result such as `10 / COUNT(*)` as an expression
on both paths, and it
fails only at runtime for an outer row without matching rows. I rebased this
PR on #60325; it now
handles only the one case `tryEvalExpr` cannot: a scalar Python UDF applied
to aggregate
functions, which is not foldable, so it stays in the `if` branch and
`ExtractPythonUDFs` lifts it
out and evaluates it on the values over zero rows for every outer row. For
such a column this PR
pulls the aggregate functions out and computes the UDF above the join; every
other column keeps
its plan. The PR now depends on #60325 and must merge after it (noted at the
top of the
description); it is stacked on it, so the diff shows #60325's commits until
that merges.
One scope note: this covers the shapes `DecorrelateInnerQuery` handles
(`LATERAL`, a scalar
subquery whose top `Aggregate` is over a lower one, `IN`). It does not cover
a scalar subquery
that is a single top-level `Aggregate`, e.g. `(SELECT inv(COUNT(*)) FROM b
WHERE b.k = a.k)`, whose
COUNT bug is handled by `constructLeftJoins`; there the Python UDF still
fails. I left that as a
follow-up and said so in the description, rather than widen this PR into the
`constructLeftJoins`
routing.
Superseded by the rework (earlier "Done" replies that no longer hold; I will
note this in the
threads):
- round 1, #4560056202 (description): the single-aggregate-function column
no longer "goes through
the pull-out"; it takes the existing path and its plan is unchanged.
- round 1, #4560056505 (tests): the test named "an expression over aggregate
functions in a
correlated subquery (scalar, LATERAL, EXISTS and IN)" no longer exists.
- round 1, #4560057477: `evalAggregateOnZeroTups` is public again, because
`DecorrelateInnerQuery`
calls it.
- round 1, #4560057742 (block comment): step 3 no longer describes "a single
function in place, an
expression above the join"; only a Python UDF column is rebuilt above the
join.
- round 1, #4560058041 (naming/dedup): there is no deduplication and no
shared pulled-out column;
`MAX(v) - MIN(v)` without a UDF is not pulled out at all.
- the literal-specific branch and the "both unreachable cases throw
internalError" change are not
in the new code: literal and plain-aggregate columns take the existing
(master) path
`if(isnull(alwaysTrue), <default>, col)`, and the single remaining
`internalError` is for a
non-aliased count-bug column, shared by the Python UDF and the plain
branch.
- spark-test replies #4550939057 (the `TODO(SPARK-61444)` is gone, now a
dependency),
#4550940205 / #4550940584 / #4550940889 (the dedup and non-determinism
tests and the
`SubquerySuite` comment they reworded were removed), and #4550939791
(nested nullability widens
only for a Python UDF column now, e.g. `named_struct('n', COUNT(*), 'u',
udf(MAX(x)))`; a
non-UDF `array(COUNT(*))` keeps its plan).
--
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]