@@ -94,7 +94,7 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Loggi
9494 case Distinct (p : Project ) =>
9595 projectToSQL(p, isDistinct = true )
9696
97- case p@ Project (_, g : Generate ) =>
97+ case p @ Project (_, g : Generate ) =>
9898 generateToSQL(p)
9999
100100 case g : Generate =>
@@ -311,18 +311,19 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Loggi
311311 (w.child.output ++ w.windowExpressions).map(_.sql).mkString(" , " ),
312312 if (w.child == OneRowRelation ) " " else " FROM" ,
313313 toSQL(w.child)
314+ )
314315 }
315316
316- /* This function handles the SQL generation for generators.
317+ /**
318+ * This function handles the SQL generation for generators.
317319 * sample plan :
318320 * +- Project [mycol2#192]
319321 * +- Generate explode(myCol#191), true, false, Some(mytable2), [mycol2#192]
320322 * +- Generate explode(array(array(1, 2, 3))), true, false, Some(mytable), [mycol#191]
321323 * +- MetastoreRelation default, src, None
322- *
323324 */
324325 private def generateToSQL (plan : Generate ): String = {
325- val columnAliases = plan.generatorOutput.map(a => quoteIdentifier(a.name) ).mkString(" ," )
326+ val columnAliases = plan.generatorOutput.map(_.sql ).mkString(" ," )
326327 val generatorAlias = if (plan.qualifier.isEmpty) " " else plan.qualifier.get
327328 val outerClause = if (plan.outer) " OUTER" else " "
328329 build(
@@ -342,8 +343,8 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Loggi
342343 }
343344
344345 private def generateToSQL (plan : Project ): String = {
345- // assert if child is a generate or not.
346346 val generate = plan.child.asInstanceOf [Generate ]
347+ assert(generate.join == true || plan.projectList.size == 1 )
347348 // Generators that appear in projection list will be expressed as LATERAL VIEW.
348349 // A qualifier is needed for a LATERAL VIEw.
349350 val generatorAlias : String = generate.qualifier.getOrElse(SQLBuilder .newGeneratorName)
0 commit comments