Skip to content
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 @@ -1131,7 +1131,7 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
* remove extra project which only re-assign expr ids from the plan so that we can identify exact
* duplicates metric definition.
*/
private def simplifyPlanForCollectedMetrics(plan: LogicalPlan): LogicalPlan = {
def simplifyPlanForCollectedMetrics(plan: LogicalPlan): LogicalPlan = {
plan.resolveOperators {
case p: Project if p.projectList.size == p.child.output.size =>
val assignExprIdOnly = p.projectList.zipWithIndex.forall {
Expand All @@ -1140,6 +1140,8 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
// ordinal of this attribute in the child outputs. So an alias-only Project means the
// the id of the aliased attribute is the same as its index in the project list.
attr.exprId.id == index
case (left: AttributeReference, index) =>
left.exprId.id == index
case _ => false
}
if (assignExprIdOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1675,4 +1675,18 @@ class AnalysisSuite extends AnalysisTest with Matchers {
checkAnalysis(ident2.select($"a"), testRelation.select($"a").analyze)
}
}

test("simplifyPlanForCollectedMetrics should handle non alias-only project case") {
val inner = Project(
Seq(
Alias(testRelation2.output(0), "a")(),
testRelation2.output(1),
Alias(testRelation2.output(2), "c")(),
testRelation2.output(3),
testRelation2.output(4)
),
testRelation2)
val actualPlan = getAnalyzer.simplifyPlanForCollectedMetrics(inner.canonicalized)
assert(actualPlan == testRelation2.canonicalized)
}
}