forked from byzer-org/byzer-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c663066
commit ca432b3
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
streamingpro-mlsql/src/main/java/streaming/dsl/mmlib/algs/SQLCacheExt.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package streaming.dsl.mmlib.algs | ||
|
||
import org.apache.spark.ml.param.Param | ||
import org.apache.spark.sql.{DataFrame, SparkSession} | ||
import org.apache.spark.sql.expressions.UserDefinedFunction | ||
import streaming.dsl.mmlib.SQLAlg | ||
import streaming.dsl.mmlib.algs.param.{BaseParams, WowParams} | ||
import streaming.session.MLSQLException | ||
|
||
|
||
class SQLCacheExt(override val uid: String) extends SQLAlg with WowParams { | ||
|
||
override def train(df: DataFrame, path: String, params: Map[String, String]): DataFrame = { | ||
|
||
val exe = params.get(execute.name).getOrElse { | ||
"cache" | ||
} | ||
|
||
if (!execute.isValid(exe)) { | ||
throw new MLSQLException(s"${execute.name} should be cache or uncache") | ||
} | ||
|
||
if (exe == "cache") { | ||
df.persist() | ||
} else { | ||
df.unpersist() | ||
} | ||
df | ||
} | ||
|
||
override def load(sparkSession: SparkSession, path: String, params: Map[String, String]): Any = { | ||
throw new RuntimeException("train is not support") | ||
} | ||
|
||
override def predict(sparkSession: SparkSession, _model: Any, name: String, params: Map[String, String]): UserDefinedFunction = { | ||
null | ||
} | ||
|
||
final val execute: Param[String] = new Param[String](this, "execute", "cache|uncache", isValid = (m: String) => { | ||
m == "cache" || m == "uncache" | ||
}) | ||
|
||
def this() = this(BaseParams.randomUID()) | ||
} |