Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/11596#discussion_r55470832 --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala --- @@ -297,6 +303,60 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Loggi ) } + /* This function handles the SQL generation when generators. + * sample plan : + * +- Project [mycol2#192] + * +- Generate explode(myCol#191), true, false, Some(mytable2), [mycol2#192] + * +- Generate explode(array(array(1, 2, 3))), true, false, Some(mytable), [mycol#191] + * +- MetastoreRelation default, src, None + * + */ + private def generateToSQL(plan: Generate): String = { + val columnAliases = plan.generatorOutput.map(a => quoteIdentifier(a.name)).mkString(",") + val generatorAlias = if (plan.qualifier.isEmpty) "" else plan.qualifier.get + val outerClause = if (plan.outer) "OUTER" else "" + build( + if (plan.child == OneRowRelation) s"(SELECT 1) ${SQLBuilder.newSubqueryName}" else toSQL(plan.child), + "LATERAL VIEW", + outerClause, + plan.generator.sql, + quoteIdentifier(generatorAlias), + "AS", + columnAliases + ) + } + + private def generateToSQL(plan: Project): String = { + // assert if child is a generate or not. --- End diff -- Please add an assert here. ``` assert(join == true || plan.projectList == 1) ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org