maropu commented on a change in pull request #28715: URL: https://github.com/apache/spark/pull/28715#discussion_r440636308
########## File path: sql/core/src/test/scala/org/apache/spark/sql/execution/WholeStageCodegenSuite.scala ########## @@ -51,6 +51,86 @@ class WholeStageCodegenSuite extends QueryTest with SharedSparkSession assert(df.collect() === Array(Row(9, 4.5))) } + test("SPARK-31897: GenerateExec should be included in WholeStageCodegen") { + import testImplicits._ + val arrayData = Seq(("James", Seq("Java", "Scala"), Map("hair" -> "black", "eye" -> "brown"))) + val df = arrayData.toDF("name", "knownLanguages", "properties") + + // Array - explode + var expDF = df.select($"name", explode($"knownLanguages"), $"properties") + var plan = expDF.queryExecution.executedPlan + assert(plan.find { + case stage: WholeStageCodegenExec => + stage.find(_.isInstanceOf[GenerateExec]).isDefined + case _ => false + }.isDefined) + checkAnswer(expDF, Array(Row("James", "Java", Map("hair" -> "black", "eye" -> "brown")), + Row("James", "Scala", Map("hair" -> "black", "eye" -> "brown")))) + + + // Map - explode + expDF = df.select($"name", $"knownLanguages", explode($"properties")) + plan = expDF.queryExecution.executedPlan + assert(plan.find { + case stage: WholeStageCodegenExec => + stage.find(_.isInstanceOf[GenerateExec]).isDefined + case _ => false + }.isDefined) + checkAnswer(expDF, + Array(Row("James", List("Java", "Scala"), "hair", "black"), + Row("James", List("Java", "Scala"), "eye", "brown"))) + + // Array - posexplode + expDF = df.select($"name", posexplode($"knownLanguages")) + plan = expDF.queryExecution.executedPlan + assert(plan.find { + case stage: WholeStageCodegenExec => + stage.find(_.isInstanceOf[GenerateExec]).isDefined + case _ => false + }.isDefined) + checkAnswer(expDF, + Array(Row("James", 0, "Java"), Row("James", 1, "Scala"))) + + // Map - posexplode + expDF = df.select($"name", posexplode($"properties")) + plan = expDF.queryExecution.executedPlan + assert(plan.find { + case stage: WholeStageCodegenExec => + stage.find(_.isInstanceOf[GenerateExec]).isDefined + case _ => false + }.isDefined) + checkAnswer(expDF, + Array(Row("James", 0, "hair", "black"), Row("James", 1, "eye", "brown"))) + Review comment: nit the single blank is enough? ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org