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

    https://github.com/apache/spark/pull/18269#discussion_r122622031
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala
 ---
    @@ -248,60 +245,94 @@ object InMemoryFileIndex extends Logging {
        * @return all children of path that match the specified filter.
        */
       private def listLeafFiles(
    -      path: Path,
    +      paths: Seq[Path],
           hadoopConf: Configuration,
           filter: PathFilter,
    -      sessionOpt: Option[SparkSession]): Seq[FileStatus] = {
    -    logTrace(s"Listing $path")
    -    val fs = path.getFileSystem(hadoopConf)
    -
    -    // [SPARK-17599] Prevent InMemoryFileIndex from failing if path 
doesn't exist
    -    // Note that statuses only include FileStatus for the files and dirs 
directly under path,
    -    // and does not include anything else recursively.
    -    val statuses = try fs.listStatus(path) catch {
    -      case _: FileNotFoundException =>
    -        logWarning(s"The directory $path was not found. Was it deleted 
very recently?")
    -        Array.empty[FileStatus]
    -    }
    -
    -    val filteredStatuses = statuses.filterNot(status => 
shouldFilterOut(status.getPath.getName))
    +      sessionOpt: Option[SparkSession]): Seq[(Path, Seq[FileStatus])] = {
    +    logTrace(s"Listing ${paths.mkString(", ")}")
    +    if (paths.isEmpty) {
    +      Nil
    +    } else {
    +      val fs = paths.head.getFileSystem(hadoopConf)
    +
    +      // [SPARK-17599] Prevent InMemoryFileIndex from failing if path 
doesn't exist
    +      // Note that statuses only include FileStatus for the files and dirs 
directly under path,
    +      // and does not include anything else recursively.
    +      val filteredStatuses = paths.flatMap { path =>
    +        try {
    +          val fStatuses = fs.listStatus(path)
    +          val filtered = fStatuses.filterNot(status => 
shouldFilterOut(status.getPath.getName))
    +          if (filtered.nonEmpty) {
    +            Some(path -> filtered)
    +          } else {
    +            None
    +          }
    +        } catch {
    +          case _: FileNotFoundException =>
    +            logWarning(s"The directory $paths was not found. Was it 
deleted very recently?")
    +            None
    +        }
    +      }
     
    -    val allLeafStatuses = {
    -      val (dirs, topLevelFiles) = filteredStatuses.partition(_.isDirectory)
    -      val nestedFiles: Seq[FileStatus] = sessionOpt match {
    -        case Some(session) =>
    -          bulkListLeafFiles(dirs.map(_.getPath), hadoopConf, filter, 
session).flatMap(_._2)
    -        case _ =>
    -          dirs.flatMap(dir => listLeafFiles(dir.getPath, hadoopConf, 
filter, sessionOpt))
    +      val allLeafStatuses = {
    +        val (dirs, topLevelFiles) = filteredStatuses.flatMap { case (path, 
fStatuses) =>
    +          fStatuses.map { f => path -> f }
    +        }.partition { case (_, fStatus) => fStatus.isDirectory }
    --- End diff --
    
    nit: `xxx.partition(_._2. isDirectory)`


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