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

    https://github.com/apache/spark/pull/11177#discussion_r52700130
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/Expand.scala ---
    @@ -71,9 +80,76 @@ case class Expand(
                 idx = 0
               }
     
    +          numOutputRows += 1
               result
             }
           }
         }
       }
    +
    +  override def upstream(): RDD[InternalRow] = {
    +    child.asInstanceOf[CodegenSupport].upstream()
    +  }
    +
    +  protected override def doProduce(ctx: CodegenContext): String = {
    +    child.asInstanceOf[CodegenSupport].produce(ctx, this)
    +  }
    +
    +  override def doConsume(ctx: CodegenContext, input: Seq[ExprCode]): 
String = {
    +    val uniqExprs: IndexedSeq[Set[Expression]] = output.indices.map { i =>
    +      projections.map(p => p(i)).toSet
    +    }
    +
    +    ctx.currentVars = input
    +    val resultVars = uniqExprs.zipWithIndex.map { case (exprs, i) =>
    +      val expr = exprs.head
    +      if (exprs.size == 1) {
    +        // it's common to have same expression for some columns in all the 
projections, for example,
    +        // GroupingSet will copy all the output from child as the first 
part of output.
    +        // We should only generate the columns once.
    +        BindReferences.bindReference(expr, child.output).gen(ctx)
    +      } else {
    +        val isNull = ctx.freshName("isNull")
    +        val value = ctx.freshName("value")
    +        val code =
    +          s"""
    +             |boolean $isNull = true;
    +             |${ctx.javaType(expr.dataType)} $value = 
${ctx.defaultValue(expr.dataType)};
    +         """.stripMargin
    +        ExprCode(code, isNull, value)
    +      }
    +    }
    +
    +    // In order to prevent code exploration, we can't call `consume()` 
many times, so we call
    +    // that in a loop, and use swith/case to select the projections.
    +    val projectCodes = projections.zipWithIndex.map { case (exprs, i) =>
    --- End diff --
    
    i find the body of this loop pretty hard to understand. can we add some 
high level comment to explain what's going on?



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