Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,14 @@ object SQLConf {
.doc("When true, the ArrayExists will follow the three-valued boolean logic.")
.booleanConf
.createWithDefault(true)

val IGNORE_DATA_LOCALITY =
Comment thread
wangshisan marked this conversation as resolved.
Outdated
buildConf("spark.sql.ignore.datalocality")
.doc("If it is set to true, Spark won't fetch the block locations for each file on " +
Comment thread
wangshisan marked this conversation as resolved.
Outdated
"listing files, which will greatly accelerate the list file operation, while loss " +
"data locality.")
.booleanConf
.createWithDefault(false)
}

/**
Expand Down Expand Up @@ -2475,6 +2483,8 @@ class SQLConf extends Serializable with Logging {

def defaultV2Catalog: Option[String] = getConf(DEFAULT_V2_CATALOG)

def ignoreDataLocality: Boolean = getConf(SQLConf.IGNORE_DATA_LOCALITY)

/** ********************** SQLConf functionality methods ************ */

/** Set Spark SQL configuration properties. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ object InMemoryFileIndex extends Logging {
isRootPath: Boolean): Seq[FileStatus] = {
logTrace(s"Listing $path")
val fs = path.getFileSystem(hadoopConf)
val ignoreLocality = sessionOpt.map(_.sqlContext.conf.ignoreDataLocality).getOrElse(false)

// Note that statuses only include FileStatus for the files and dirs directly under path,
// and does not include anything else recursively.
Expand All @@ -299,7 +300,7 @@ object InMemoryFileIndex extends Logging {
// to retrieve the file status with the file block location. The reason to still fallback
// to listStatus is because the default implementation would potentially throw a
// FileNotFoundException which is better handled by doing the lookups manually below.
case _: DistributedFileSystem =>
case _: DistributedFileSystem if !ignoreLocality =>
val remoteIter = fs.listLocatedStatus(path)
new Iterator[LocatedFileStatus]() {
def next(): LocatedFileStatus = remoteIter.next
Expand Down Expand Up @@ -376,7 +377,7 @@ object InMemoryFileIndex extends Logging {
// - Here we are calling `getFileBlockLocations` in a sequential manner, but it should not
// be a big deal since we always use to `bulkListLeafFiles` when the number of
// paths exceeds threshold.
case f =>
case f if !ignoreLocality =>
// The other constructor of LocatedFileStatus will call FileStatus.getPermission(),
// which is very slow on some file system (RawLocalFileSystem, which is launch a
// subprocess and parse the stdout).
Expand All @@ -400,6 +401,8 @@ object InMemoryFileIndex extends Logging {
missingFiles += f.getPath.toString
None
}

case f => Some(f)
}

if (missingFiles.nonEmpty) {
Expand Down