Skip to content

Commit

Permalink
Revert "[SPARK-43979][SQL][FOLLOWUP] transformUpWithNewOutput` should…
Browse files Browse the repository at this point in the history
… only be used with new outputs"

This reverts commit b8204d1.
  • Loading branch information
dongjoon-hyun committed Aug 11, 2023
1 parent 98cd980 commit 898f3d8
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1071,13 +1071,13 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
def check(plan: LogicalPlan): Unit = plan.foreach { node =>
node match {
case metrics @ CollectMetrics(name, _, _) =>
val simplifiedMetrics = simplifyPlanForCollectedMetrics(metrics.canonicalized)
val simplifiedMetrics = simplifyPlanForCollectedMetrics(metrics)
metricsMap.get(name) match {
case Some(other) =>
val simplifiedOther = simplifyPlanForCollectedMetrics(other.canonicalized)
val simplifiedOther = simplifyPlanForCollectedMetrics(other)
// Exact duplicates are allowed. They can be the result
// of a CTE that is used multiple times or a self join.
if (simplifiedMetrics != simplifiedOther) {
if (!simplifiedMetrics.sameResult(simplifiedOther)) {
failAnalysis(
errorClass = "DUPLICATED_METRICS_NAME",
messageParameters = Map("metricName" -> name))
Expand All @@ -1102,17 +1102,17 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
* duplicates metric definition.
*/
private def simplifyPlanForCollectedMetrics(plan: LogicalPlan): LogicalPlan = {
plan.resolveOperators {
plan.transformUpWithNewOutput {
case p: Project if p.projectList.size == p.child.output.size =>
val assignExprIdOnly = p.projectList.zip(p.child.output).forall {
case (left: Alias, right: Attribute) =>
left.child.semanticEquals(right) && right.name == left.name
case _ => false
}
if (assignExprIdOnly) {
p.child
(p.child, p.output.zip(p.child.output))
} else {
p
(p, Nil)
}
}
}
Expand Down

0 comments on commit 898f3d8

Please sign in to comment.