Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26352][SQL][FOLLOWUP-2.4] Fix missing sameOutput in branch-2.4 #23330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,29 @@ object ReorderJoin extends Rule[LogicalPlan] with PredicateHelper {
createOrderedJoin(input, conditions)
}

if (p.sameOutput(reordered)) {
if (sameOutput(p, reordered)) {
reordered
} else {
// Reordering the joins have changed the order of the columns.
// Inject a projection to make sure we restore to the expected ordering.
Project(p.output, reordered)
}
}

/**
* Returns true iff output of both plans are semantically the same, ie.:
* - they contain the same number of `Attribute`s;
* - references are the same;
* - the order is equal too.
* NOTE: this is copied over from SPARK-25691 from master.
*/
def sameOutput(plan1: LogicalPlan, plan2: LogicalPlan): Boolean = {
val output1 = plan1.output
val output2 = plan2.output
output1.length == output2.length && output1.zip(output2).forall {
case (a1, a2) => a1.semanticEquals(a2)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,28 @@ class JoinReorderSuite extends PlanTest with StatsEstimationTestBase {
val optimized = Optimize.execute(analyzed)
val expected = groundTruthBestPlan.analyze

assert(analyzed.sameOutput(expected)) // if this fails, the expected plan itself is incorrect
assert(analyzed.sameOutput(optimized))
assert(sameOutput(analyzed, expected)) // if this fails, the expected plan itself is incorrect
assert(sameOutput(analyzed, optimized))

compareJoinOrder(optimized, expected)
}

private def outputsOf(plans: LogicalPlan*): Seq[Attribute] = {
plans.map(_.output).reduce(_ ++ _)
}

/**
* Returns true iff output of both plans are semantically the same, ie.:
* - they contain the same number of `Attribute`s;
* - references are the same;
* - the order is equal too.
* NOTE: this is copied over from SPARK-25691 from master.
*/
def sameOutput(plan1: LogicalPlan, plan2: LogicalPlan): Boolean = {
val output1 = plan1.output
val output2 = plan2.output
output1.length == output2.length && output1.zip(output2).forall {
case (a1, a2) => a1.semanticEquals(a2)
}
}
}