Skip to content

Commit efb65e0

Browse files
yu-iskwmengxr
authored andcommitted
[SPARK-13265][ML] Refactoring of basic ML import/export for other file system besides HDFS
jkbradley I tried to improve the function to export a model. When I tried to export a model to S3 under Spark 1.6, we couldn't do that. So, it should offer S3 besides HDFS. Can you review it when you have time? Thanks! Author: Yu ISHIKAWA <[email protected]> Closes #11151 from yu-iskw/SPARK-13265.
1 parent c86009c commit efb65e0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mllib/src/main/scala/org/apache/spark/ml/util/ReadWrite.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package org.apache.spark.ml.util
1919

2020
import java.io.IOException
2121

22-
import org.apache.hadoop.fs.{FileSystem, Path}
22+
import org.apache.hadoop.fs.Path
2323
import org.json4s._
24-
import org.json4s.JsonDSL._
2524
import org.json4s.jackson.JsonMethods._
25+
import org.json4s.JsonDSL._
2626

2727
import org.apache.spark.{Logging, SparkContext}
2828
import 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

Comments
 (0)