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

    https://github.com/apache/spark/pull/18075#discussion_r121989572
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/ColumnarBatchScan.scala 
---
    @@ -93,7 +93,7 @@ private[sql] trait ColumnarBatchScan extends 
CodegenSupport {
         }
     
         val nextBatch = ctx.freshName("nextBatch")
    --- End diff --
    
    I suppose it depends on which implementation we think is cleaner. The 
freshName generated by the caller is typically used twice, once in the call to 
`addNewFunction`, but also immediately in the function code as the method name. 
If we use a name hint, we'd have to do a string `replace` inside 
`addNewFunction` to update the placeholder method name with the freshname. So 
it would seem either we keep
    
    ```
        val nextBatch = ctx.freshName("nextBatch")
        val nextBatchFuncName = ctx.addNewFunction(nextBatch,
          s"""
             |private void $nextBatch() throws java.io.IOException {
             |  long getBatchStart = System.nanoTime();
             |  if ($input.hasNext()) {
             |    $batch = ($columnarBatchClz)$input.next();
             |    $numOutputRows.add($batch.numRows());
             |    $idx = 0;
             |    ${columnAssigns.mkString("", "\n", "\n")}
             |  }
             |  $scanTimeTotalNs += System.nanoTime() - getBatchStart;
             |}""".stripMargin)
    ```
    
    or we have
    
    ```
        val nextBatchHint = "nextBatch"
        val nextBatch = ctx.addNewFunction(nextBatchHint,
          s"""
             |private void $nextBatchHint() throws java.io.IOException {
             |  long getBatchStart = System.nanoTime();
             |  if ($input.hasNext()) {
             |    $batch = ($columnarBatchClz)$input.next();
             |    $numOutputRows.add($batch.numRows());
             |    $idx = 0;
             |    ${columnAssigns.mkString("", "\n", "\n")}
             |  }
             |  $scanTimeTotalNs += System.nanoTime() - getBatchStart;
             |}""".stripMargin)
    ```
    
    where `addNewFunction` would do the proper replacement over the code for 
the method with a freshname generated from "nextBatch" as a name hint.
    
    Or in every instance, we just duplicate the string hint without creating a 
variable for it in both the `addNewFunction` call and the method name:
    
    ```
        val nextBatch = ctx.addNewFunction("nextBatch",
          s"""
             |private void nextBatch() throws java.io.IOException {
             |  long getBatchStart = System.nanoTime();
             |  if ($input.hasNext()) {
             |    $batch = ($columnarBatchClz)$input.next();
             |    $numOutputRows.add($batch.numRows());
             |    $idx = 0;
             |    ${columnAssigns.mkString("", "\n", "\n")}
             |  }
             |  $scanTimeTotalNs += System.nanoTime() - getBatchStart;
             |}""".stripMargin)
    ```
    
    Which would you prefer? 


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to