Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/9454#discussion_r44074302
--- Diff: mllib/src/main/scala/org/apache/spark/ml/util/ReadWrite.scala ---
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.ml.util
+
+import java.{util => ju}
+import java.io.IOException
+
+import scala.annotation.varargs
+import scala.collection.mutable
+import scala.collection.JavaConverters._
+
+import org.apache.hadoop.fs.{FileSystem, Path}
+import org.json4s._
+import org.json4s.JsonDSL._
+import org.json4s.jackson.JsonMethods._
+
+import org.apache.spark.{Logging, SparkContext}
+import org.apache.spark.annotation.{Experimental, Since}
+import org.apache.spark.ml.param.{ParamPair, Params}
+import org.apache.spark.sql.SQLContext
+import org.apache.spark.util.Utils
+
+/**
+ * Trait for [[Writer]] and [[Reader]].
+ */
+private[util] sealed trait BaseReadWrite {
+ private var optionSQLContext: Option[SQLContext] = None
+
+ /**
+ * Sets the SQL context to use for saving/loading.
+ */
+ @Since("1.6.0")
+ def context(sqlContext: SQLContext): this.type = {
+ optionSQLContext = Option(sqlContext)
+ this
+ }
+
+ /**
+ * Returns the user-specified SQL context or the default.
+ */
+ protected final def sqlContext: SQLContext = optionSQLContext.getOrElse {
+ SQLContext.getOrCreate(SparkContext.getOrCreate())
+ }
+}
+
+/**
+ * Abstract class for utility classes that can save ML instances.
+ */
+@Experimental
+@Since("1.6.0")
+abstract class Writer extends BaseReadWrite {
+
+ protected var shouldOverwrite: Boolean = false
+
+ /**
+ * Saves the ML instance to the input path.
+ */
+ @Since("1.6.0")
+ @throws[IOException]("If the input path already exists but overwrite is
not enabled.")
+ def to(path: String): Unit
+
+ /**
+ * Saves the ML instances to the input path, the same as [[to()]].
+ */
+ @Since("1.6.0")
+ @throws[IOException]("If the input path already exists but overwrite is
not enabled.")
+ def save(path: String): Unit = to(path)
+
+ /**
+ * Overwrites if the output path already exists.
+ */
+ def overwrite(): this.type = {
+ shouldOverwrite = true
+ this
+ }
+}
+
+/**
+ * Trait for classes that provide [[Writer]].
+ */
+@Since("1.6.0")
+trait Writable {
+
+ /**
+ * Returns a [[Writer]] instance for this ML instance.
+ */
+ @Since("1.6.0")
+ def write: Writer
+}
+
+/**
+ * Abstract class for utility classes that can load ML instances.
+ * @tparam T ML instance type
+ */
+@Experimental
+@Since("1.6.0")
+abstract class Reader[T] extends BaseReadWrite {
+
+ /**
+ * Loads the ML component from the input path.
+ */
+ @Since("1.6.0")
+ def from(path: String): T
+
+ /**
+ * Loads the ML component from the input path, the same as [[from()]].
+ */
+ def load(path: String): T = from(path)
+}
+
+/**
+ * Trait for objects that provide [[Reader]].
+ * @tparam T ML instance type
+ */
+@Experimental
+@Since("1.6.0")
+trait Readable[T] {
+
+ /**
+ * Returns a [[Reader]] instance for this class.
+ */
+ @Since("1.6.0")
+ def read: Reader[T]
+}
+
+/**
+ * Default [[Writer]] implementation for non-meta transformers and
estimators.
--- End diff --
"non-meta transformers and estimators" --> "transformers and estimators
which contain basic (json4s-serializable) Params and no data. This will not
handle more complex Params or types with data (e.g., models with coefficients)."
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]