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/20 13:47:56 UTC
[GitHub] [spark] cloud-fan commented on a diff in pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
cloud-fan commented on code in PR #36281:
URL: https://github.com/apache/spark/pull/36281#discussion_r854157760
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/DistinctKeyVisitor.scala:
##########
@@ -29,25 +29,21 @@ object DistinctKeyVisitor extends LogicalPlanVisitor[Set[ExpressionSet]] {
private def projectDistinctKeys(
keys: Set[ExpressionSet], projectList: Seq[NamedExpression]): Set[ExpressionSet] = {
val outputSet = ExpressionSet(projectList.map(_.toAttribute))
- val aliases = projectList.filter(_.isInstanceOf[Alias])
+ val aliases = projectList.collect {
+ // TODO: Expand distinctKeys for redundant aliases on the same expression
+ case alias: Alias if alias.child.deterministic => alias.child.canonicalized -> alias
+ }.toMap
if (aliases.isEmpty) {
keys.filter(_.subsetOf(outputSet))
} else {
- val aliasedDistinctKeys = keys.map { expressionSet =>
- expressionSet.map { expression =>
- expression transform {
- case expr: Expression =>
- // TODO: Expand distinctKeys for redundant aliases on the same expression
- aliases
- .collectFirst { case a: Alias if a.child.semanticEquals(expr) => a.toAttribute }
- .getOrElse(expr)
- }
- }
- }
+ val aliasedDistinctKeys = keys.map(_.map(_.transform {
+ case expr: Expression =>
+ aliases.get(expr.canonicalized).map(_.toAttribute).getOrElse(expr)
+ }))
Review Comment:
```suggestion
val aliasedDistinctKeys = keys.map(_.map(_.transform {
case expr: Expression =>
aliases.get(expr.canonicalized).map(_.toAttribute).getOrElse(expr)
}))
```
--
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