Skip to content
Closed
Changes from all commits
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
26 changes: 14 additions & 12 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ private[spark] object Utils extends Logging {
val targetFile = new File(targetDir, filename)
val uri = new URI(url)
val fileOverwrite = conf.getBoolean("spark.files.overwrite", defaultValue = false)
uri.getScheme match {
case "http" | "https" | "ftp" =>
Option(uri.getScheme) match {
case Some("http") | Some("https") | Some("ftp") =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being late on this, but I'd really rather not see things like case Some("http") | Some("https") | Some("ftp") =>. Instead, I'd do this as:

Option(uri.getScheme).getOrElse("file") match {
  case "http" | "https" | "ftp" => ...
  case "file" => ...
  case _ =>
}

logInfo("Fetching " + url + " to " + tempFile)

var uc: URLConnection = null
Expand Down Expand Up @@ -374,7 +374,7 @@ private[spark] object Utils extends Logging {
}
}
Files.move(tempFile, targetFile)
case "file" | null =>
case Some("file") | None =>
// In the case of a local file, copy the local file to the target directory.
// Note the difference between uri vs url.
val sourceFile = if (uri.isAbsolute) new File(uri) else new File(url)
Expand Down Expand Up @@ -403,7 +403,7 @@ private[spark] object Utils extends Logging {
logInfo("Copying " + sourceFile.getAbsolutePath + " to " + targetFile.getAbsolutePath)
Files.copy(sourceFile, targetFile)
}
case _ =>
case Some(other) =>
// Use the Hadoop filesystem library, which supports file://, hdfs://, s3://, and others
val fs = getHadoopFileSystem(uri, hadoopConf)
val in = fs.open(new Path(uri))
Expand Down Expand Up @@ -1368,16 +1368,17 @@ private[spark] object Utils extends Logging {
if (uri.getPath == null) {
throw new IllegalArgumentException(s"Given path is malformed: $uri")
}
uri.getScheme match {
case windowsDrive(d) if windows =>

Option(uri.getScheme) match {
case Some(windowsDrive(d)) if windows =>
new URI("file:/" + uri.toString.stripPrefix("/"))
case null =>
case None =>
// Preserve fragments for HDFS file name substitution (denoted by "#")
// For instance, in "abc.py#xyz.py", "xyz.py" is the name observed by the application
val fragment = uri.getFragment
val part = new File(uri.getPath).toURI
new URI(part.getScheme, part.getPath, fragment)
case _ =>
case Some(other) =>
uri
}
}
Expand All @@ -1399,10 +1400,11 @@ private[spark] object Utils extends Logging {
} else {
paths.split(",").filter { p =>
val formattedPath = if (windows) formatWindowsPath(p) else p
new URI(formattedPath).getScheme match {
case windowsDrive(d) if windows => false
case "local" | "file" | null => false
case _ => true
val uri = new URI(formattedPath)
Option(uri.getScheme) match {
case Some(windowsDrive(d)) if windows => false
case Some("local") | Some("file") | None => false
case Some(other) => true
}
}
}
Expand Down