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

    https://github.com/apache/spark/pull/18309#discussion_r122497071
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala ---
    @@ -126,6 +126,35 @@ private[sql] trait SQLTestUtils
       }
     
       /**
    +   * Generates the requested number of temporary paths without creating the
    +   * actual files/directories and passes these to the provided function 
'f'.
    +   * Deletes any files/directories left at these paths after 'f' returns.
    +   *
    +   * @param numPaths Number of paths to create
    +   * @param f Function to invoke with the created paths
    +   */
    +  protected def withTempPaths(numPaths: Int)(f: List[File] => Unit) {
    +    def addPaths(numPaths: Int, paths: List[File]): List[File] = {
    +
    +      if (numPaths <= 0) {
    +        paths
    +      } else {
    +        val path = Utils.createTempDir()
    +        path.delete()
    +        addPaths(numPaths - 1, path :: paths)
    +      }
    +    }
    +
    +    val paths = addPaths(numPaths, List.empty)
    +
    +    try {
    +      f(paths)
    +    } finally {
    +      paths.foreach(path => Utils.deleteRecursively(path))
    +    }
    +  }
    --- End diff --
    
    I personally think It's strange to use a recursive function, does the 
following modified function work for your test?
    ```
    
      protected def withTempDirs(num: Int)(body: Seq[File] => Unit) {
        val files = mutable.Buffer[File]()
        for (i <- 0 until num) {
          files += Utils.createTempDir().getCanonicalFile
        }
        try {
          body(files)
        } finally {
          files.foreach(Utils.deleteRecursively)
        }
      }
    ```


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