Github user brkyvz commented on a diff in the pull request:
https://github.com/apache/spark/pull/15235#discussion_r80574449
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ListingFileCatalog.scala
---
@@ -82,73 +85,185 @@ class ListingFileCatalog(
* This is publicly visible for testing.
*/
def listLeafFiles(paths: Seq[Path]): mutable.LinkedHashSet[FileStatus] =
{
- if (paths.length >=
sparkSession.sessionState.conf.parallelPartitionDiscoveryThreshold) {
- HadoopFsRelation.listLeafFilesInParallel(paths, hadoopConf,
sparkSession)
- } else {
- // Right now, the number of paths is less than the value of
- // parallelPartitionDiscoveryThreshold. So, we will list file
statues at the driver.
- // If there is any child that has more files than the threshold, we
will use parallel
- // listing.
-
- // Dummy jobconf to get to the pathFilter defined in configuration
- val jobConf = new JobConf(hadoopConf, this.getClass)
- val pathFilter = FileInputFormat.getInputPathFilter(jobConf)
-
- val statuses: Seq[FileStatus] = paths.flatMap { path =>
- val fs = path.getFileSystem(hadoopConf)
- logTrace(s"Listing $path on driver")
-
- val childStatuses = {
- try {
- val stats = fs.listStatus(path)
- if (pathFilter != null) stats.filter(f =>
pathFilter.accept(f.getPath)) else stats
- } catch {
- case _: FileNotFoundException =>
- logWarning(s"The directory $path was not found. Was it
deleted very recently?")
- Array.empty[FileStatus]
- }
- }
+ val files =
+ if (paths.length >=
sparkSession.sessionState.conf.parallelPartitionDiscoveryThreshold) {
+ ListingFileCatalog.listLeafFilesInParallel(paths, hadoopConf,
sparkSession)
+ } else {
+ ListingFileCatalog.listLeafFilesInSerial(paths, hadoopConf)
+ }
+
+ mutable.LinkedHashSet(files: _*)
+ }
+
+ override def equals(other: Any): Boolean = other match {
+ case hdfs: ListingFileCatalog => paths.toSet == hdfs.paths.toSet
+ case _ => false
+ }
+
+ override def hashCode(): Int = paths.toSet.hashCode()
+}
+
+
+object ListingFileCatalog extends Logging {
+
+ // `FileStatus` is Writable but not serializable. What make it worse,
somehow it doesn't play
+ // well with `SerializableWritable`. So there seems to be no way to
serialize a `FileStatus`.
+ // Here we use `SerializableFileStatus` to extract key components of a
`FileStatus` to serialize
+ // it from executor side and reconstruct it on driver side.
+ private case class SerializableBlockLocation(
+ names: Array[String],
+ hosts: Array[String],
+ offset: Long,
+ length: Long)
+
+ private case class SerializableFileStatus(
+ path: String,
+ length: Long,
+ isDir: Boolean,
+ blockReplication: Short,
+ blockSize: Long,
+ modificationTime: Long,
+ accessTime: Long,
+ blockLocations: Array[SerializableBlockLocation])
+
+ /**
+ * List a collection of path recursively.
+ */
+ private def listLeafFilesInSerial(
+ paths: Seq[Path],
+ hadoopConf: Configuration): Seq[FileStatus] = {
+ // Dummy jobconf to get to the pathFilter defined in configuration
+ val jobConf = new JobConf(hadoopConf, this.getClass)
+ val filter = FileInputFormat.getInputPathFilter(jobConf)
+
+ paths.flatMap { path =>
+ logTrace(s"Listing $path")
+ val fs = path.getFileSystem(hadoopConf)
+
+ // [SPARK-17599] Prevent ListingFileCatalog from failing if path
doesn't exist
+ val status: Option[FileStatus] = try Option(fs.getFileStatus(path))
catch {
--- End diff --
I don't think you need this. You are increasing the number of `getStatus`
calls that we need to make. There is no guarantee that the folder will exist
once `listLeafFiles0` is called.
---
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]