Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5383#discussion_r28306055
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/Generate.scala ---
    @@ -56,28 +65,33 @@ case class Generate(
       val boundGenerator = BindReferences.bindReference(generator, 
child.output)
     
       override def execute(): RDD[Row] = {
    +    // boundGenerator.terminate() should be triggered after all of the 
rows in the partition
         if (join) {
           child.execute().mapPartitions { iter =>
    -        val nullValues = Seq.fill(generator.output.size)(Literal(null))
    -        // Used to produce rows with no matches when outer = true.
    -        val outerProjection =
    -          newProjection(child.output ++ nullValues, child.output)
    -
    -        val joinProjection =
    -          newProjection(child.output ++ generatorOutput, child.output ++ 
generatorOutput)
    +        val generatorNullRow = 
Row.fromSeq(Seq.fill[Any](generator.output.size)(null))
             val joinedRow = new JoinedRow
     
             iter.flatMap {row =>
    +          // we should always set the left (child output)
    +          joinedRow.withLeft(row)
               val outputRows = boundGenerator.eval(row)
               if (outer && outputRows.isEmpty) {
    -            outerProjection(row) :: Nil
    +            joinedRow.withRight(generatorNullRow) :: Nil
               } else {
    -            outputRows.map(or => joinProjection(joinedRow(row, or)))
    +            outputRows.map(or => joinedRow.withRight(or))
               }
    +        } ++ LazyIterator(() => boundGenerator.terminate()).map { row =>
    --- End diff --
    
    I think we can just use `org.apache.spark.util.CompletionIterator` to 
ensure `terminate()` is called at the very last.


---
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

Reply via email to