dongjoon-hyun commented on code in PR #60773:
URL: https://github.com/apache/spark/pull/60773#discussion_r4656673590
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala:
##########
@@ -274,19 +286,32 @@ trait PredicateHelper extends AliasHelper with Logging {
case a: Attribute if below.contains(a) => a
})
case agg: Aggregate =>
+ val below = failableOutput(agg.child)
AttributeSet(agg.aggregateExpressions.flatMap {
case a: Alias =>
val result = a.child.transform { case e: AggregateExpression =>
e.resultAttribute }
- if (result.deterministic &&
!ExprUtils.canEvaluateUnconditionally(result)) {
+ if (result.deterministic &&
(!ExprUtils.canEvaluateUnconditionally(result) ||
+ result.references.exists(below.contains))) {
Some(a.toAttribute)
} else {
None
}
+ case a: Attribute if below.contains(a) => Some(a)
case _ => None
})
case j: Join => failableOutput(j.left) ++ failableOutput(j.right)
- case _: Filter | _: Sample | _: LocalLimit | _: GlobalLimit | _: Offset |
_: Sort =>
+ case u: Union =>
+ val children = u.children.map(c => (c.output, failableOutput(c)))
+ AttributeSet(u.output.zipWithIndex.collect {
+ case (a, i) if children.exists { case (output, failable) =>
+ failable.contains(output(i))
+ } => a
+ })
+ case _: Filter | _: Sample | _: LocalLimit | _: GlobalLimit | _: Offset |
_: Sort |
+ _: Window | _: EventTimeWatermark =>
Review Comment:
One correction to the split: a window no longer counts as having computed
the column at the join. Once an equality over both sides is in the join
condition, `ColumnPruning` can remove a window whose results are not read, and
the join then reads the column from the projection below. With `SELECT /*+
BROADCAST(b) */ a.k, b.k FROM (SELECT k, count(*) OVER (PARTITION BY k) AS w
FROM (SELECT 10L / (s - 3) AS k FROM pt)) a, pt2 b WHERE rand(10) * 10 > 100
AND a.k = b.k`, the previous commit failed with `DIVIDE_BY_ZERO`, as the base
branch does, while the first commit returned no row. So `atJoin` now stops only
at a watermark, a repartition and a grouping key, and through a window such an
equality stays above the join, as through a union. `DataFrameSuite` has a case
for it, and the plan test expects the equality above the join for the window
side.
--
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]