Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/11854#discussion_r56773705
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -1194,6 +1195,41 @@ object RemoveDispensableExpressions extends
Rule[LogicalPlan] {
}
/**
+ * Removes useless Distinct that are not necessary.
+ */
+object EliminateDistinct extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan transform {
+ // Eliminate the useless distinct.
+ // Distinct has been replaced by Aggregate in the rule
ReplaceDistinctWithAggregate
+ case a @ Aggregate(grouping, aggs, child) if isDistinct(a) &&
isDistinct(child) => child
+ }
+
+ // propagate the distinct property from the child
+ @tailrec
--- End diff --
Another solution is to add a property `isDistinct` to `LogicalPlan`.
However, it could be expensive for recursive calls, compared with the
`@tailrec`. In the future, if the physical plan will use the property
`isDistinct`, we can rewrite it. Actually, this is a very critical property in
runtime. Thanks!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]