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 @@ -381,6 +381,10 @@ object ColumnPruning extends Rule[LogicalPlan] {
p
}

// Eliminate the child from the Projects with no references to its child
case p @ Project(projectList, child) if p.references.intersect(child.outputSet).isEmpty =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this will change the number of rows right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. I think it is changed to 1 row. Indeed this causes problem.

Project(projectList, OneRowRelation)

// Can't prune the columns on LeafNode
case p @ Project(_, l: LeafNode) => p

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,19 @@ class ColumnPruningSuite extends PlanTest {
comparePlans(Optimize.execute(plan1.analyze), correctAnswer1)
}

test("Eliminate the Project with no references to its child") {
val expectedInput = OneRowRelation
val expected = Project(Literal(1).as("1") :: Nil, expectedInput).analyze

val input = LocalRelation('key.int, 'value.string)
val query1 =
Project(Literal(1).as("1") :: Nil, Project(Literal(1).as("1") :: Nil, input)).analyze
comparePlans(Optimize.execute(query1), expected)

val query2 =
Project(Literal(1).as("1") :: Nil, Project(Nil, input)).analyze
comparePlans(Optimize.execute(query2), expected)
}

// todo: add more tests for column pruning
}