[SPARK-14970][SQL] Prevent DataSource from enumerates all files in a directory if there is user specified schema
## What changes were proposed in this pull request? The FileCatalog object gets created even if the user specifies schema, which means files in the directory is enumerated even thought its not necessary. For large directories this is very slow. User would want to specify schema in such scenarios of large dirs, and this defeats the purpose quite a bit. ## How was this patch tested? Hard to test this with unit test. Author: Tathagata Das <tathagata.das1565@gmail.com> Closes #12748 from tdas/SPARK-14970.
This commit is contained in:
parent
d5ab42ceb9
commit
0ee5419b6c
|
@ -127,6 +127,7 @@ case class DataSource(
|
|||
}
|
||||
|
||||
private def inferFileFormatSchema(format: FileFormat): StructType = {
|
||||
userSpecifiedSchema.orElse {
|
||||
val caseInsensitiveOptions = new CaseInsensitiveMap(options)
|
||||
val allPaths = caseInsensitiveOptions.get("path")
|
||||
val globbedPaths = allPaths.toSeq.flatMap { path =>
|
||||
|
@ -135,9 +136,7 @@ case class DataSource(
|
|||
val qualified = hdfsPath.makeQualified(fs.getUri, fs.getWorkingDirectory)
|
||||
SparkHadoopUtil.get.globPathIfNecessary(qualified)
|
||||
}.toArray
|
||||
|
||||
val fileCatalog: FileCatalog = new HDFSFileCatalog(sparkSession, options, globbedPaths, None)
|
||||
userSpecifiedSchema.orElse {
|
||||
format.inferSchema(
|
||||
sparkSession,
|
||||
caseInsensitiveOptions,
|
||||
|
|
Loading…
Reference in a new issue