srowen commented on a change in pull request #25899: SPARK-29089
DataFrameReader bottleneck in DataSource#checkAndGlobPathIfNecessary when
reading large amount of S3 files
URL: https://github.com/apache/spark/pull/25899#discussion_r327164735
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala
##########
@@ -734,30 +734,45 @@ object DataSource extends Logging {
* Checks and returns files in all the paths.
*/
private[sql] def checkAndGlobPathIfNecessary(
- paths: Seq[String],
+ pathStrings: Seq[String],
hadoopConf: Configuration,
checkEmptyGlobPath: Boolean,
checkFilesExist: Boolean): Seq[Path] = {
- val allGlobPath = paths.flatMap { path =>
- val hdfsPath = new Path(path)
- val fs = hdfsPath.getFileSystem(hadoopConf)
- val qualified = hdfsPath.makeQualified(fs.getUri, fs.getWorkingDirectory)
- val globPath = SparkHadoopUtil.get.globPathIfNecessary(fs, qualified)
-
- if (checkEmptyGlobPath && globPath.isEmpty) {
- throw new AnalysisException(s"Path does not exist: $qualified")
+ val qualifiedPaths = pathStrings
+ .map{pathString =>
+ val path = new Path(pathString)
+ val fs = path.getFileSystem(hadoopConf)
+ path.makeQualified(fs.getUri, fs.getWorkingDirectory)
}
- // Sufficient to check head of the globPath seq for non-glob scenario
- // Don't need to check once again if files exist in streaming mode
- if (checkFilesExist && !fs.exists(globPath.head)) {
- throw new AnalysisException(s"Path does not exist: ${globPath.head}")
+ // Split the paths into glob and non glob paths, because we don't need to
do an existence check
+ // for globbed paths.
+ val globPaths = qualifiedPaths
+ .filter(path => SparkHadoopUtil.get.isGlobPath(path))
+ val nonGlobPaths = qualifiedPaths
+ .filter(path => !SparkHadoopUtil.get.isGlobPath(path))
+
+ val globbedPaths = globPaths.par.flatMap { globPath =>
Review comment:
Yeah good point, we want to try to use ThreadUtils to avoid reusing the
global thread pool
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]