Skip to content

[SPARK-52079][SQL][Followup] Normalize internal projections under Aggregate as well #50953

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -154,11 +154,17 @@ object NormalizePlan extends PredicateHelper {
.getTagValue(DeduplicateRelations.PROJECT_FOR_EXPRESSION_ID_DEDUPLICATION)
.isDefined =>
project.child
case aggregate @ Aggregate(_, _, innerProject: Project, _) =>
val newInnerProject = Project(
innerProject.projectList.sortBy(_.name),
innerProject.child
)
aggregate.copy(child = newInnerProject)
case Project(outerProjectList, innerProject: Project) =>
val normalizedInnerProjectList = normalizeProjectList(innerProject.projectList)
val orderedInnerProjectList = normalizedInnerProjectList.sortBy(_.name)
val newInnerProject =
Project(orderedInnerProjectList, innerProject.child)
val newInnerProject = Project(
innerProject.projectList.sortBy(_.name),
innerProject.child
)
Project(normalizeProjectList(outerProjectList), newInnerProject)
case Project(projectList, child) =>
Project(normalizeProjectList(projectList), child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NormalizePlanSuite extends SparkFunSuite with SQLConfHelper {
assert(NormalizePlan(baselinePlan) == NormalizePlan(testPlan))
}

test("Normalize ordering in a project list of an inner Project") {
test("Normalize ordering in a project list of an inner Project of Project") {
val baselinePlan =
LocalRelation($"col1".int, $"col2".string).select($"col1", $"col2").select($"col1")
val testPlan =
Expand All @@ -58,6 +58,16 @@ class NormalizePlanSuite extends SparkFunSuite with SQLConfHelper {
assert(NormalizePlan(baselinePlan) == NormalizePlan(testPlan))
}

test("Normalize ordering in a project list of an inner Project of Aggregate") {
val baselinePlan =
LocalRelation($"col1".int, $"col2".string).select($"col1", $"col2").groupBy($"col1")($"col1")
val testPlan =
LocalRelation($"col1".int, $"col2".string).select($"col2", $"col1").groupBy($"col1")($"col1")

assert(baselinePlan != testPlan)
assert(NormalizePlan(baselinePlan) == NormalizePlan(testPlan))
}

test("Normalize InheritAnalysisRules expressions") {
val castWithoutTimezone =
Cast(child = Literal(1), dataType = BooleanType, ansiEnabled = conf.ansiEnabled)
Expand Down