@@ -23,6 +23,7 @@ import scala.collection.JavaConverters._
2323import scala .language .{existentials , implicitConversions }
2424import scala .util .{Failure , Success , Try }
2525
26+ import org .apache .hadoop .conf .Configuration
2627import org .apache .hadoop .fs .Path
2728
2829import org .apache .spark .deploy .SparkHadoopUtil
@@ -538,23 +539,8 @@ case class DataSource(
538539 checkFilesExist : Boolean ): Seq [Path ] = {
539540 val allPaths = caseInsensitiveOptions.get(" path" ) ++ paths
540541 val hadoopConf = sparkSession.sessionState.newHadoopConf()
541- allPaths.flatMap { path =>
542- val hdfsPath = new Path (path)
543- val fs = hdfsPath.getFileSystem(hadoopConf)
544- val qualified = hdfsPath.makeQualified(fs.getUri, fs.getWorkingDirectory)
545- val globPath = SparkHadoopUtil .get.globPathIfNecessary(fs, qualified)
546-
547- if (checkEmptyGlobPath && globPath.isEmpty) {
548- throw new AnalysisException (s " Path does not exist: $qualified" )
549- }
550-
551- // Sufficient to check head of the globPath seq for non-glob scenario
552- // Don't need to check once again if files exist in streaming mode
553- if (checkFilesExist && ! fs.exists(globPath.head)) {
554- throw new AnalysisException (s " Path does not exist: ${globPath.head}" )
555- }
556- globPath
557- }.toSeq
542+ DataSource .checkAndGlobPathIfNecessary(allPaths.toSeq, hadoopConf,
543+ checkEmptyGlobPath, checkFilesExist)
558544 }
559545}
560546
@@ -701,6 +687,33 @@ object DataSource extends Logging {
701687 }
702688 }
703689
690+ /**
691+ * Checks and returns files in all the paths.
692+ */
693+ private [sql] def checkAndGlobPathIfNecessary (
694+ paths : Seq [String ],
695+ hadoopConf : Configuration ,
696+ checkEmptyGlobPath : Boolean ,
697+ checkFilesExist : Boolean ): Seq [Path ] = {
698+ paths.flatMap { path =>
699+ val hdfsPath = new Path (path)
700+ val fs = hdfsPath.getFileSystem(hadoopConf)
701+ val qualified = hdfsPath.makeQualified(fs.getUri, fs.getWorkingDirectory)
702+ val globPath = SparkHadoopUtil .get.globPathIfNecessary(fs, qualified)
703+
704+ if (checkEmptyGlobPath && globPath.isEmpty) {
705+ throw new AnalysisException (s " Path does not exist: $qualified" )
706+ }
707+
708+ // Sufficient to check head of the globPath seq for non-glob scenario
709+ // Don't need to check once again if files exist in streaming mode
710+ if (checkFilesExist && ! fs.exists(globPath.head)) {
711+ throw new AnalysisException (s " Path does not exist: ${globPath.head}" )
712+ }
713+ globPath
714+ }
715+ }
716+
704717 /**
705718 * When creating a data source table, the `path` option has a special meaning: the table location.
706719 * This method extracts the `path` option and treat it as table location to build a
0 commit comments