You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/04/13 16:52:26 UTC
[GitHub] [spark] sigmod commented on a diff in pull request #36177: [SPARK-38886][SQL] Remove outer join if aggregate functions are duplicate agnostic on streamed side
sigmod commented on code in PR #36177:
URL: https://github.com/apache/spark/pull/36177#discussion_r849692135
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala:
##########
@@ -184,6 +202,23 @@ object EliminateOuterJoin extends Rule[LogicalPlan] with PredicateHelper {
case a @ Aggregate(_, _, p @ Project(_, Join(_, right, RightOuter, _, _)))
if a.groupOnly && p.references.subsetOf(right.outputSet) =>
a.copy(child = p.copy(child = right))
+
+ case a @ Aggregate(_, aggExprs, Join(left, _, LeftOuter, _, _))
+ if a.references.subsetOf(left.outputSet) &&
+ !hasNotDuplicateAgnosticAggregateFunction(aggExprs) =>
Review Comment:
Nit: how about:
`allDuplicateAgnostic(aggExprs)`
Double negatives seem harder to read.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala:
##########
@@ -166,6 +176,14 @@ object EliminateOuterJoin extends Rule[LogicalPlan] with PredicateHelper {
}
}
+ private def hasNotDuplicateAgnosticAggregateFunction(
+ aggregateExpressions: Seq[NamedExpression]): Boolean = {
+ aggregateExpressions.exists(_.exists {
+ case agg: AggregateFunction => !EliminateDistinct.isDuplicateAgnostic(agg)
Review Comment:
Does it make sense to all check `deterministic` in `isDuplicateAgnostic`?
E.g., the rewrite doesn't work for
`SELECT t1.c1, min(t1.c2 * rand()) FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 GROUP BY t1.c1`
or
`SELECT t1.c1, min(udf(t1.c2)) FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 GROUP BY t1.c1`
where udf is non deterministic?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org