Skip to content

Commit

Permalink
convert options in include statment to set statments (byzer-org#1633)
Browse files Browse the repository at this point in the history
* convert options in include statment to set statments

* add test and fix exception throws when no suffix in  include statement

* ignore result check in pr_1633.mlsql

revise the code example

add checking multi group params

revise the remind msg when setting multi-group params in the Discretizer et

rename the checking functions
  • Loading branch information
allwefantasy authored and ckeys committed Dec 30, 2021
1 parent 00b0fb8 commit 63d7b88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,28 @@ class ScriptIncludeSource extends IncludeSource with Logging {
case "byzer" | "byz" | "by" | "py" =>
newPathChunk = newPathChunk.dropRight(1)
suffix = pathChunk.last
case _ =>


}

newPathChunk.drop(1).foreach { item =>
rootPath.add(item)
}

val finalPath = rootPath.toPath + "." + suffix

Source.fromFile(finalPath).getLines().mkString("\n")
val action = options.getOrElse("__action__", "set")
val leftParams = options - "__action__"

val generateCode = action match {
case "set" => leftParams.map { item =>
s"""set ${item._1}='''${item._2}''';"""
}.mkString("\n")
case _ => ""
}

generateCode + Source.fromFile(finalPath).getLines().mkString("\n")
}

override def skipPathPrefix: Boolean = true
Expand Down
8 changes: 8 additions & 0 deletions streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--%comparator=tech.mlsql.it.IgnoreResultComparator

include lib.`gitee.com/allwefantasy/lib-core`
where alias="libCore";

include local.`libCore.udf.hello`;
select hello() as name as output;
!assert output ''' :name == "hello world" ''' "output should be 'hello world'";
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,17 @@ class SQLDiscretizer(override val uid: String) extends SQLAlg with Functions wit
return metas
}

def checkWithoutGroupParams(params: Map[String, String]): Unit = {
val group = params.map(p => {
val key = p._1
key.contains(DiscretizerParamsConstrant.PARAMS_PREFIX + ".")
}).filter(_ == true)
require(group.size == 0, "The multi-group params are not available for the Discretizer Et!")
}

def trainWithoutGroup(df: DataFrame, params: Map[String, String], _method: String, metaPath: String): DataFrame = {
val dfWithId = df.withColumn("id", monotonically_increasing_id)
checkWithoutGroupParams(params)
var transformedDF = dfWithId
// we need save metadatas with index, because we need index
val metas: Array[(Int, DiscretizerTrainData)] = {
Expand Down Expand Up @@ -220,10 +229,14 @@ class SQLDiscretizer(override val uid: String) extends SQLAlg with Functions wit
|
|train data1 as Discretizer.`/tmp/model`
|where method="bucketizer"
|and `fitParam.0.inputCol`="a"
|and `fitParam.0.splitArray`="-inf,0.0,1.0,inf"
|and `fitParam.1.inputCol`="b"
|and `fitParam.1.splitArray`="-inf,0.0,1.0,inf";
|and `inputCol`="a"
|and `splits`="-inf,0.0,1.0,inf";
|
|train data1 as Discretizer.`/tmp/discretizer`
|where method="quantile"
|and `inputCol`="a"
|and `outputCol`="a_v"
|and `numBuckets`="3";
|;
""".stripMargin)

Expand Down

0 comments on commit 63d7b88

Please sign in to comment.