Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22630#discussion_r223025094
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala ---
    @@ -66,27 +75,22 @@ trait BaseLimitExec extends UnaryExecNode with 
CodegenSupport {
       // to the parent operator.
       override def usedInputs: AttributeSet = AttributeSet.empty
     
    +  private lazy val countTerm = BaseLimitExec.newLimitCountTerm()
    +
    +  override lazy val limitNotReachedChecks: Seq[String] = {
    +    s"$countTerm < $limit" +: super.limitNotReachedChecks
    +  }
    +
       protected override def doProduce(ctx: CodegenContext): String = {
         child.asInstanceOf[CodegenSupport].produce(ctx, this)
       }
     
       override def doConsume(ctx: CodegenContext, input: Seq[ExprCode], row: 
ExprCode): String = {
    -    val stopEarly =
    -      ctx.addMutableState(CodeGenerator.JAVA_BOOLEAN, "stopEarly") // init 
as stopEarly = false
    -
    -    ctx.addNewFunction("stopEarly", s"""
    -      @Override
    -      protected boolean stopEarly() {
    -        return $stopEarly;
    -      }
    -    """, inlineToOuterClass = true)
    -    val countTerm = ctx.addMutableState(CodeGenerator.JAVA_INT, "count") 
// init as count = 0
    +    ctx.addMutableState(CodeGenerator.JAVA_INT, countTerm, forceInline = 
true, useFreshName = false)
    --- End diff --
    
    because the counter variable name is decided before we obtain the 
`CodegenContext`. If we don't inline here, we need a way to notify the upstream 
operators about the counter name, which is hard to do.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to