Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -171,8 +171,23 @@ object ColumnPruning extends Rule[LogicalPlan] {

Project(substitutedProjection, child)

case gen@Generate(generator: Explode, isJoin, isOuter, alias, child) =>
val allReferences = gen.references ++ gen.parentReferences
val pruneProject = prunedChild(child, allReferences)
Generate(generator, isJoin, isOuter, alias, pruneProject)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that OK if we just do like

case gen @ Generate(_, _, _, _, child) 
  if (child.outputSet -- gen.references).nonEmpty =>
  gen.copy(child = Project(a.references.toSeq, child))

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we don't need other code change except the unit test.

Copy link
Author

Choose a reason for hiding this comment

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

Ok,thanks:)


// Eliminate no-op Projects
case Project(projectList, child) if child.output == projectList => child

case plan =>
plan.children.foreach { c =>
c match {
case gen@Generate(generator: Explode, isJoin, isOuter, alias, child) =>
gen.parentReferences = plan.references;
case _ => // nothing
}
}
plan
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is no longer needed.

}

/** Applies a projection only when the child is producing unnecessary attributes */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ case class Generate(
child: LogicalPlan)
extends UnaryNode {

var parentReferences:AttributeSet = AttributeSet(Seq.empty)

Copy link
Contributor

Choose a reason for hiding this comment

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

This mutable state is no longer needed.

protected def generatorOutput: Seq[Attribute] = {
val output = alias
.map(a => generator.output.map(_.withQualifiers(a :: Nil)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
INSERT OVERWRITE TABLE episodes_part PARTITION (doctor_pt=1)
SELECT title, air_date, doctor FROM episodes
""".cmd
)
),
TestTable("person",
("CREATE TABLE person(name string, age int, data array<INT>) " +
"ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' " +
"COLLECTION ITEMS TERMINATED BY ':'").cmd,
s"LOAD DATA LOCAL INPATH '${getHiveFile("data/files/person.txt")}' INTO TABLE person".cmd
)
)

hiveQTestUtilTables.foreach(registerTestTable)
Expand Down
5 changes: 5 additions & 0 deletions sql/hive/src/test/resources/data/files/person.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A, 20, 10:12:19
B, 25, 7:8:4
C, 19, 12:4:232
D, 73, 243:53:7835
E, 88, 1345:23:532532:353
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ class PruningSuite extends HiveComparisonTest with BeforeAndAfter {
Seq("key"),
Seq.empty)

createPruningTest("Column pruning - explode with aggregate",
"SELECT name, sum(d) AS sumd FROM person LATERAL VIEW explode(data) d AS d GROUP BY name",
Seq("name", "sumd"),
Seq("data","name"),
Seq.empty)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to go all the way to hive to create an integration test. Instead create some unit tests in ...catalyst.optimizer.


createPruningTest("Column pruning - outer explode with limit",
"SELECT name FROM person LATERAL VIEW OUTER explode(data) outd AS d limit 3",
Seq("name"),
Seq("data","name"),
Seq.empty)



// Partition pruning tests

createPruningTest("Partition pruning - non-partitioned, non-trivial project",
Expand Down