@@ -19,10 +19,10 @@ package org.apache.spark.ml.util
1919
2020import java .io .IOException
2121
22- import org .apache .hadoop .fs .{ FileSystem , Path }
22+ import org .apache .hadoop .fs .Path
2323import org .json4s ._
24- import org .json4s .JsonDSL ._
2524import org .json4s .jackson .JsonMethods ._
25+ import org .json4s .JsonDSL ._
2626
2727import org .apache .spark .{Logging , SparkContext }
2828import org .apache .spark .annotation .{Experimental , Since }
@@ -75,13 +75,14 @@ abstract class MLWriter extends BaseReadWrite with Logging {
7575 @ throws[IOException ](" If the input path already exists but overwrite is not enabled." )
7676 def save (path : String ): Unit = {
7777 val hadoopConf = sc.hadoopConfiguration
78- val fs = FileSystem .get(hadoopConf)
79- val p = new Path (path)
80- if (fs.exists(p)) {
78+ val outputPath = new Path (path)
79+ val fs = outputPath.getFileSystem(hadoopConf)
80+ val qualifiedOutputPath = outputPath.makeQualified(fs.getUri, fs.getWorkingDirectory)
81+ if (fs.exists(qualifiedOutputPath)) {
8182 if (shouldOverwrite) {
8283 logInfo(s " Path $path already exists. It will be overwritten. " )
8384 // TODO: Revert back to the original content if save is not successful.
84- fs.delete(p , true )
85+ fs.delete(qualifiedOutputPath , true )
8586 } else {
8687 throw new IOException (
8788 s " Path $path already exists. Please use write.overwrite().save(path) to overwrite it. " )
0 commit comments