dongjoon-hyun commented on a change in pull request #24637: [SPARK-27707][SQL] 
Prune unnecessary nested fields from Generate
URL: https://github.com/apache/spark/pull/24637#discussion_r304500435
 
 

 ##########
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ColumnPruningSuite.scala
 ##########
 @@ -101,6 +103,56 @@ class ColumnPruningSuite extends PlanTest {
     comparePlans(optimized, correctAnswer)
   }
 
+  test("Nested column pruning for Generate") {
+    def runTest(
+        origGenerator: Generator,
+        replacedGenerator: Seq[String] => Generator,
+        aliasedExprs: Seq[String] => Seq[Expression],
+        unrequiredChildIndex: Seq[Int]) {
+      withSQLConf(SQLConf.NESTED_PRUNING_ON_EXPRESSIONS.key -> "true") {
+        val structType = StructType.fromDDL("d double, e array<string>, f 
double, g double")
+        val input = LocalRelation('a.int, 'b.int, 'c.struct(structType))
+
+        val query =
+          input
+            .generate(origGenerator, outputNames = "generator" :: Nil)
+            .select('a, 'c.getField("d"), 'generator)
+            .analyze
+
+        val optimized = Optimize.execute(query)
+
+        val aliases = 
NestedColumnAliasingSuite.collectGeneratedAliases(optimized)
+
+        val selectedFields = UnresolvedAttribute("a") +: aliasedExprs(aliases)
+        val correctAnswer =
+          input
+            .select(selectedFields: _*)
+            .generate(replacedGenerator(aliases),
+              unrequiredChildIndex = unrequiredChildIndex,
+              outputNames = "generator" :: Nil)
+            .select('a, $"${aliases(0)}".as("c.d"), 'generator)
+            .analyze
+
+        comparePlans(optimized, correctAnswer)
+      }
+    }
+
+    runTest(
+      Explode('c.getField("e")),
+      aliases => Explode($"${aliases(1)}".as("c.e")),
+      aliases => Seq('c.getField("d").as(aliases(0)), 
'c.getField("e").as(aliases(1))),
+      Seq(2)
+    )
+    runTest(Stack(2 :: 'c.getField("f") :: 'c.getField("g") :: Nil),
 
 Review comment:
   Thank you for adding more tests, @viirya !

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to