dongjoon-hyun commented on code in PR #60643:
URL: https://github.com/apache/spark/pull/60643#discussion_r4608498068
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala:
##########
@@ -233,12 +234,17 @@ trait PredicateHelper extends AliasHelper with Logging {
/**
* The output columns of `plan` that can fail to compute: the deterministic
columns of a
* [[Project]] whose expression [[ExprUtils.canEvaluateUnconditionally]]
rejects or reads such a
- * column of its child, looking through [[Filter]] and [[Sample]]. A
condition over such a column
- * can fail as its expression does: under whole-stage codegen, the
projection computes a
- * deterministic column for a row only when a condition above first reads
it, and
+ * column of its child, and the result columns of an [[Aggregate]] whose
expression, with each
+ * aggregate function taken as its value, is deterministic and rejected by
it. A [[Filter]],
+ * [[Sample]], [[LocalLimit]], [[GlobalLimit]], [[Offset]] or [[Join]]
passes such columns of
+ * its children through. A condition over such a column can fail as its
expression does: under
+ * whole-stage codegen, the projection or aggregation computes a
deterministic column for a row
Review Comment:
Thanks. I narrowed the wording: only an aggregation with grouping keys under
whole-stage codegen computes a result column lazily, so the case is
conservative for the others, e.g. a global aggregation or
`ObjectHashAggregateExec`. I kept the match as is, since a global aggregation
outputs one row and an inferred filter over its result cannot be pushed below
it anyway.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala:
##########
@@ -249,8 +255,20 @@ trait PredicateHelper extends AliasHelper with Logging {
a.child.references.exists(below.contains)) => a.toAttribute
case a: Attribute if below.contains(a) => a
})
- case Filter(_, child) => failableOutput(child)
- case s: Sample => failableOutput(s.child)
+ case agg: Aggregate =>
+ AttributeSet(agg.aggregateExpressions.flatMap {
+ case a: Alias =>
+ val result = a.child.transform { case e: AggregateExpression =>
e.resultAttribute }
+ if (result.deterministic &&
!ExprUtils.canEvaluateUnconditionally(result)) {
+ Some(a.toAttribute)
+ } else {
+ None
+ }
+ case _ => None
+ })
+ case j: Join => failableOutput(j.left) ++ failableOutput(j.right)
+ case _: Filter | _: Sample | _: LocalLimit | _: GlobalLimit | _: Offset =>
Review Comment:
Right. On 4.3.0, `range(0, 10, 1, 4)` gets an `Exchange SinglePartition`
below `GlobalLimit 8`, and the query fails with `DIVIDE_BY_ZERO` even with
`spark.sql.constraintPropagation.enabled=false`. I said in the comment and in
the description that a global limit or an offset helps only when its input has
a single partition.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala:
##########
@@ -233,12 +234,17 @@ trait PredicateHelper extends AliasHelper with Logging {
/**
* The output columns of `plan` that can fail to compute: the deterministic
columns of a
Review Comment:
Sure. I split it into three lists and condensed the table from the
description there.
--
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]